Email: sales@ip2location.com
Web Site: http://www.ip2location.com
Copyright (c) 2003 by Hexa Software Development Center
The database format is known as Comma Separated Values (CSV). All fields are separated by a comma and each individual line is a record by itself.
[ Back to Top ]Column Number |
Column Descriptions |
1 | Beginning IP Number |
2 | Ending IP Number |
3 | ISO 3166 Country Code (2 Characters) |
4 | Full Country Name |
For example:
"IP_FROM","IP_TO","COUNTRY_CODE","COUNTRY_NAME"
"3401056256","3401400319","MY","MALAYSIA"
Column Number |
Column Descriptions |
Column Values |
1 | Beginning IP Number | 3401056256 |
2 | Ending IP Number | 3401400319 |
3 | ISO 3166 Country Code (2 Characters) | MY |
4 | Full Country Name | MALAYSIA |
IP address (IPV4) is divided into 4 sub-blocks. Each sub-block has a
different weight number each powered by 256. IP number is being used in the
database because it is efficient to search between a range of number in
database.
Beginning IP number and Ending IP Number are calculated based on following
formula:
IP Number = 16777216*w + 65536*x + 256*y +
z (1)
where
IP Address = w.x.y.z
For example, if IP address is "202.186.13.4", then its IP Number "3401190660" is
based on the formula (1).
IP Address = 202.186.13.4
So, w = 202, x = 186, y = 13 and z = 4
IP Number = 16777216*202 + 65536*186 + 256*13 + 4
= 3388997632 + 12189696 +
3328 + 4
= 3401190660
To reverse IP number to IP address,
w = int ( IP Number / 16777216 ) % 256
x = int ( IP Number / 65536 ) % 256
y = int ( IP Number / 256 ) % 256
z = int ( IP Number
) % 256
where % is the mod operator and
int is return the integer part of the
division.
Example ASP Function To Convert IP Address to IP Number
Function Dot2LongIP (ByVal DottedIP)
Dim i, pos
Dim PrevPos, num
If DottedIP = "" Then
Dot2LongIP = 0
Else
For i = 1 To 4
pos = InStr(PrevPos + 1, DottedIP,
".", 1)
If i = 4 Then
pos =
Len(DottedIP) + 1
End If
num = Int(Mid(DottedIP, PrevPos + 1,
pos - PrevPos - 1))
PrevPos = pos
Dot2LongIP = ((num Mod 256) * (256 ^
(4 - i))) + Dot2LongIP
Next
End If
End Function
Example PHP Function To Convert IP Address to IP Number
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 +
$ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}
Search the IP-Country database to match a unique record that has the IP
Number fits between Beginning IP Number and Ending IP Number.
For example, IP Address "202.186.13.4" is equivalent to IP Number "3401190660".
It belongs to the following record in the database because it is between the
beginning and the ending of IP number.
"3401056256","3401400319","MY","MALAYSIA"
From the recordset, the Country Name is Malaysia and Country Code is MY.
First, import this database into your MS-SQL, MS-ACCESS, PL/SQL, MySQL or
other RDMS. Use a query string to get matching recordset.
Example of SQL Query
SELECT [COUNTRY NAME COLUMN] FROM [IP-COUNTRY
TABLE] WHERE
[SEARCH IP NO] BETWEEN [IP FROM COLUMN] AND [IP TO COLUMN]
The IP address is available from the web server variable "REMOTE_ADDR".
ASP without Proxy detection
<%
ipaddress = Request.ServerVariables("REMOTE_ADDR")
%>
ASP with Proxy detection
<%
ipaddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if ipaddress = "" then
ipaddress =
Request.ServerVariables("REMOTE_ADDR")
end if
%>
PHP without Proxy detection
<?
$ipaddress = getenv(REMOTE_ADDR);
?>
PHP with Proxy detection
<?
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ipaddress =
getenv(HTTP_X_FORWARDED_FOR);
} else {
$ipaddress = getenv(REMOTE_ADDR);
}
?>
JSP without Proxy detection
<%
String ipaddress = request.getRemoteAddr();
%>
JSP with Proxy detection
<%
if (request.getHeader("HTTP_X_FORWARDED_FOR") == null) {
String ipaddress =
request.getRemoteAddr();
} else {
String ipaddress =
request.getHeader("HTTP_X_FORWARDED_FOR");
}
%>
ColdFusion without Proxy detection
<CFCOMPONENT>
<CFSET ipaddress="#CGI.Remote_Addr#">
</CFCOMPONENT>
ColdFusion with Proxy detection
<CFCOMPONENT>
<CFIF #CGI.HTTP_X_Forwarded_For# EQ "">
<CFSET ipaddress="#CGI.Remote_Addr#">
<CFELSE>
<CFSET ipaddress="#CGI.HTTP_X_Forwarded_For#">
</CFIF>
</CFCOMPONENT>
MS-SQL
CREATE TABLE [dbo].[IPCountry] (
[ipFROM] [float] NOT NULL ,
[ipTO] [float] NOT NULL ,
[countrySHORT] [nvarchar] (2) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[countryLONG] [nvarchar] (45) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
) ON [PRIMARY]
GO
MYSQL
CREATE TABLE IPCountry
(
ipFROM DOUBLE NOT NULL,
ipTO DOUBLE NOT NULL,
countrySHORT VARCHAR(2) NOT NULL,
countryLONG VARCHAR(45) NOT NULL,
PRIMARY KEY(ipFROM, ipTO)
);
Please take note that the data types of ipFROM and ipTO columns. It must be at
least 4 bytes to store integer number range from 0 - 4294967296.
i. Create and connect to 'ip2Location' database
mysql> CREATE DATABASE ip2location
mysql> CONNECT ip2location
ii. Create 'ipcountry' table
mysql> CREATE TABLE IPCountry
--> (
--> ipFROM DOUBLE NOT NULL,
--> ipTO DOUBLE NOT NULL,
--> countrySHORT VARCHAR(2) NOT NULL,
--> countryLONG VARCHAR(45) NOT NULL,
--> PRIMARY KEY(ipFROM, ipTO)
--> );
iii.Import the 'ipcountry.csv' database into table 'ipcountry'
mysql> LOAD DATA INFILE "<path>/IPCountry.csv"
INTO TABLE IPCountry FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED
BY '\r';
We also provide a mysqldump file "ipcountry.mysql.dump" for direct database
restore.
There are only 100 records in the demo version. The full version of database has more than 55000 records.
[ Back to Top ]You can subscribe to free 3rd party web-hosting that support server-side scripting. One example is Brinster.com. If you do not want to install this demo, you can visit our pre-installed demo at http://www.ip2location.com/test/ipcountry.asp.
[ Back to Top ]Ownership of IP addresses changing hands from time to time. Therefore, a small percent of IP address blocks need to be updated every year. Our database is updated monthly to make sure it is always correct. We will give you free one year update if you purchase the database now.
[ Back to Top ]a) Fill-up the online purchase form
https://www.regsoft.net/regsoft/vieworderpage.php3?productid=50951.
b) We will generate an unique login/password to allow you downloading the
database for one year after we received your order.
You will receive login and password through email immediately after payment authorized. You can use your credential to download the database from our web anytime. The database is in ZIP compressed format to save your bandwidth and downloading time.
[ Back to Top ]Number of License | Price |
1 | US$49 |
2 | US$89 |
5 | US$179 |
10 | US$299 |
Corporate | US$499 |
You can resell our databases provided you purchase a separate license for each client. For example, if you are a developer and purchase a license for your client, you can make whatever changes you need and deliver it to your client - provided you transfer the license to your client (as easy as notification through email). In other words, one copy cannot be sold to multiple parties. You can resell the database for whatever price you wish.
[ Back to Top ]If you've subscribed to IP-COUNTRY [DB1] database or ActiveX/DLL [AX1], you can purchase an upgrade pack
to download IP-COUNTRY-ISP database. The upgrade pack is available at
US$150/license. Please proceed to this secure online form to order
https://www.regsoft.net/purchase.php3?productid=57739.
You can purchase an upgrade pack to download IP-COUNTRY-REGION-CITY-ISP database available at US$300/license.
Please proceed to this secure online form to order https://www.regsoft.net/purchase.php3?productid=59155
The IP-Country database has over 95% in level of accuracy, which is higher than any of our competitors.
The inaccuracy is due to dynamic IP address allocation by large ISPs such as AOL and MSN
TV. Because AOL uses a network that routes all of the company's Internet traffic
through Reston, Virginia. All IP-based geo-location services, including
IP2Location, are unable to determine the state and city for people who dial into
the AOL network.
Country Code | Country Name | Number of IP Address |
AD | ANDORRA | 8195 |
AE | UNITED ARAB EMIRATES | 418813 |
AF | AFGHANISTAN | 4152 |
AG | ANTIGUA AND BARBUDA | 24213 |
AI | ANGUILLA | 1344 |
AL | ALBANIA | 15624 |
AM | ARMENIA | 43960 |
AN | NETHERLANDS ANTILLES | 24206 |
AO | ANGOLA | 20306 |
AP | ASIA PACIFIC | 36752 |
AQ | ANTARCTICA | 512 |
AR | ARGENTINA | 1432200 |
AS | AMERICAN SAMOA | 2304 |
AT | AUSTRIA | 6122485 |
AU | AUSTRALIA | 21875117 |
AW | ARUBA | 5376 |
AZ | AZERBAIJAN | 51336 |
BA | BOSNIA AND HERZEGOWINA | 80460 |
BB | BARBADOS | 29600 |
BD | BANGLADESH | 179948 |
BE | BELGIUM | 5792042 |
BF | BURKINA FASO | 10240 |
BG | BULGARIA | 725645 |
BH | BAHRAIN | 21114 |
BI | BURUNDI | 1040 |
BJ | BENIN | 6464 |
BM | BERMUDA | 62989 |
BN | BRUNEI DARUSSALAM | 33793 |
BO | BOLIVIA | 82096 |
BR | BRAZIL | 10763563 |
BS | BAHAMAS | 34224 |
BT | BHUTAN | 8192 |
BV | BOUVET ISLAND | 1312 |
BW | BOTSWANA | 6560 |
BY | BELARUS | 76769 |
BZ | BELIZE | 13456 |
CA | CANADA | 48907353 |
CD | CONGO, THE DEMOCRATIC REPUBLIC OF THE | 1520 |
CF | CENTRAL AFRICAN REPUBLIC | 564 |
CG | CONGO | 1304 |
CH | SWITZERLAND | 13125987 |
CI | COTE D'IVOIRE | 20430 |
CK | COOK ISLANDS | 8208 |
CL | CHILE | 1806733 |
CM | CAMEROON | 13480 |
CN | CHINA | 37007177 |
CO | COLOMBIA | 539449 |
CR | COSTA RICA | 122288 |
CS | CZECHOSLOVAKIA (FORMER) | 32552 |
CU | CUBA | 22094 |
CV | CAPE VERDE | 1024 |
CY | CYPRUS | 129037 |
CZ | CZECH REPUBLIC | 2683561 |
DE | GERMANY | 64163716 |
DJ | DJIBOUTI | 296 |
DK | DENMARK | 5220717 |
DM | DOMINICA | 6456 |
DO | DOMINICAN REPUBLIC | 65113 |
DZ | ALGERIA | 78248 |
EC | ECUADOR | 180225 |
EE | ESTONIA | 395330 |
EG | EGYPT | 912942 |
ER | ERITREA | 1680 |
ES | SPAIN | 10273735 |
ET | ETHIOPIA | 16640 |
EU | EUROPEAN UNION | 37434937 |
FI | FINLAND | 8873597 |
FJ | FIJI | 84480 |
FK | FALKLAND ISLANDS (MALVINAS) | 256 |
FM | MICRONESIA, FEDERATED STATES OF | 768 |
FO | FAROE ISLANDS | 16776 |
FR | FRANCE | 56732029 |
FX | FRANCE, METROPOLITAN | 16 |
GA | GABON | 7696 |
GB | GREAT BRITAIN | 7168 |
GD | GRENADA | 5960 |
GE | GEORGIA | 132424 |
GH | GHANA | 46040 |
GI | GIBRALTAR | 33300 |
GL | GREENLAND | 8448 |
GM | GAMBIA | 8192 |
GN | GUINEA | 71848 |
GP | GUADELOUPE | 2376 |
GQ | EQUATORIAL GUINEA | 188 |
GR | GREECE | 2194018 |
GT | GUATEMALA | 42852 |
GU | GUAM | 126544 |
GW | GUINEA-BISSAU | 912 |
GY | GUYANA | 8360 |
HK | HONG KONG | 5451955 |
HM | HEARD ISLAND AND MCDONALD ISLANDS | 18 |
HN | HONDURAS | 25916 |
HR | CROATIA | 293342 |
HT | HAITI | 40384 |
HU | HUNGARY | 2029083 |
ID | INDONESIA | 1395508 |
IE | IRELAND | 1746877 |
IL | ISRAEL | 3607933 |
IN | INDIA | 3051068 |
IO | BRITISH INDIAN OCEAN TERRITORY | 4096 |
IQ | IRAQ | 96 |
IR | IRAN, ISLAMIC REPUBLIC OF | 657434 |
IS | ICELAND | 488518 |
IT | ITALY | 22063551 |
JM | JAMAICA | 53833 |
JO | JORDAN | 138208 |
JP | JAPAN | 87931785 |
KE | KENYA | 96985 |
KG | KYRGYZSTAN | 49664 |
KH | CAMBODIA | 24832 |
KI | KIRIBATI | 1024 |
KM | COMOROS | 192 |
KN | SAINT KITTS AND NEVIS | 4504 |
KP | KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF | 96 |
KR | KOREA, REPUBLIC OF | 29374217 |
KW | KUWAIT | 465607 |
KY | CAYMAN ISLANDS | 6296 |
KZ | KAZAKSTAN | 172910 |
LA | LAO PEOPLE'S DEMOCRATIC REPUBLIC | 26128 |
LB | LEBANON | 81425 |
LC | SAINT LUCIA | 2224 |
LI | LIECHTENSTEIN | 26341 |
LK | SRI LANKA | 163344 |
LR | LIBERIA | 1920 |
LS | LESOTHO | 5152 |
LT | LITHUANIA | 400515 |
LU | LUXEMBOURG | 786338 |
LV | LATVIA | 487840 |
LY | LIBYAN ARAB JAMAHIRIYA | 18704 |
MA | MOROCCO | 158696 |
MC | MONACO | 31586 |
MD | MOLDOVA, REPUBLIC OF | 59992 |
MG | MADAGASCAR | 9988 |
MH | MARSHALL ISLANDS | 328 |
MK | MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF | 123920 |
ML | MALI | 6800 |
MM | MYANMAR | 16640 |
MN | MONGOLIA | 58120 |
MO | MACAU | 63781 |
MP | NORTHERN MARIANA ISLANDS | 9584 |
MQ | MARTINIQUE | 3912 |
MR | MAURITANIA | 11449 |
MS | MONTSERRAT | 272 |
MT | MALTA | 195880 |
MU | MAURITIUS | 19988 |
MV | MALDIVES | 12288 |
MW | MALAWI | 5376 |
MX | MEXICO | 4806994 |
MY | MALAYSIA | 1837160 |
MZ | MOZAMBIQUE | 23987 |
NA | NAMIBIA | 28390 |
NC | NEW CALEDONIA | 26152 |
NE | NIGER | 3350 |
NG | NIGERIA | 173152 |
NI | NICARAGUA | 24680 |
NL | NETHERLANDS | 30318053 |
NO | NORWAY | 8703134 |
NP | NEPAL | 60874 |
NR | NAURU | 8224 |
NZ | NEW ZEALAND | 3788384 |
OM | OMAN | 166680 |
PA | PANAMA | 201666 |
PE | PERU | 391382 |
PF | FRENCH POLYNESIA | 10000 |
PG | PAPUA NEW GUINEA | 37636 |
PH | PHILIPPINES | 953945 |
PK | PAKISTAN | 317698 |
PL | POLAND | 4492521 |
PR | PUERTO RICO | 146125 |
PS | PALESTINIAN TERRITORY, OCCUPIED | 59283 |
PT | PORTUGAL | 1789528 |
PW | PALAU | 8704 |
PY | PARAGUAY | 21336 |
QA | QATAR | 29953 |
RE | REUNION | 6 |
RO | ROMANIA | 1195680 |
RU | RUSSIAN FEDERATION | 7211276 |
RW | RWANDA | 6384 |
SA | SAUDI ARABIA | 635278 |
SB | SOLOMON ISLANDS | 8704 |
SC | SEYCHELLES | 1024 |
SD | SUDAN | 10240 |
SE | SWEDEN | 14778929 |
SG | SINGAPORE | 2204718 |
SI | SLOVENIA | 632282 |
SK | SLOVAKIA | 890782 |
SL | SIERRA LEONE | 5857 |
SM | SAN MARINO | 8581 |
SN | SENEGAL | 14824 |
SO | SOMALIA | 1228 |
SR | SURINAME | 1856 |
ST | SAO TOME AND PRINCIPE | 512 |
SV | EL SALVADOR | 38847 |
SY | SYRIAN ARAB REPUBLIC | 34752 |
SZ | SWAZILAND | 14672 |
TC | TURKS AND CAICOS ISLANDS | 1920 |
TD | CHAD | 308 |
TF | FRENCH SOUTHERN TERRITORIES | 256 |
TG | TOGO | 8992 |
TH | THAILAND | 1939075 |
TJ | TAJIKISTAN | 4704 |
TK | TOKELAU | 16 |
TM | TURKMENISTAN | 5632 |
TN | TUNISIA | 41488 |
TO | TONGA | 5376 |
TP | EAST TIMOR | 1280 |
TR | TURKEY | 2639957 |
TT | TRINIDAD AND TOBAGO | 30240 |
TV | TUVALU | 8448 |
TW | TAIWAN, PROVINCE OF CHINA | 12835040 |
TZ | TANZANIA, UNITED REPUBLIC OF | 24764 |
UA | UKRAINE | 989935 |
UG | UGANDA | 16536 |
UK | UNITED KINGDOM | 83690976 |
UM | UNITED STATES MINOR OUTLYING ISLANDS | 88 |
US | UNITED STATES | 550596534 |
UY | URUGUAY | 168649 |
UZ | UZBEKISTAN | 34232 |
VA | HOLY SEE (VATICAN CITY STATE) | 11008 |
VC | SAINT VINCENT AND THE GRENADINES | 640 |
VE | VENEZUELA | 1038549 |
VG | VIRGIN ISLANDS, BRITISH | 12841 |
VI | VIRGIN ISLANDS, U.S. | 10432 |
VN | VIET NAM | 160880 |
VU | VANUATU | 8192 |
WS | SAMOA | 10752 |
YE | YEMEN | 9480 |
YU | SERBIA AND MONTENEGRO | 516704 |
ZA | SOUTH AFRICA | 6404353 |
ZM | ZAMBIA | 11906 |
ZW | ZIMBABWE | 27951 |