Email: sales@ip2location.com
Web Site: http://www.ip2location.com
Copyright (c) 2002-2005 by IP2Location.com
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);
}
}
Example ColdFusion Function To Convert IP Address to IP Number
<cfset ipaddress="#cgi.remote_addr#">
<cfset a = ListFirst(ipaddress,".")>
<cfset a_rest = ListRest(ipaddress, ".")>
<cfset b = ListFirst(a_rest, ".")>
<cfset b_rest = ListRest(a_rest, ".")>
<cfset c = ListFirst(b_rest, ".")>
<cfset c_rest = ListRest(b_rest,".")>
<cfset d = ListFirst(c_rest, ".")>
<cfset ipnumber = 16777216*a + 65536*b + 256*c + d>
Example C# Function To Convert IP Address to IP Number
public double Dot2LongIP(string DottedIP)
{
int i;
string [] arrDec;
double num = 0;
if (DottedIP == "")
{
return 0;
}
else
{
arrDec = DottedIP.Split('.');
for(i = arrDec.Length - 1; i >= 0 ; i --)
{
num += ((int.Parse(arrDec[i])%256) * Math.Pow(256 ,(3 - i )));
}
return num;
}
}
Example VB.NET Function To Convert IP Address to IP Number
Public Function Dot2LongIP(ByVal DottedIP As String) As Double
Dim arrDec() As String
Dim i As Integer
Dim intResult As Long
If DottedIP = "" then
Dot2LongIP = 0
Else
arrDec = DottedIP.Split(".")
For i = arrDec.Length - 1 To 0 Step -1
intResult = intResult + ((Int(arrDec(i)) Mod 256) * Math.Pow(256, 3 -i))
Next
Dot2LongIP = intResult
End If
End Function
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>
ASP.NET (C#) without Proxy detection
public string IpAddress()
{
return Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
}
ASP.NET (C#) with Proxy detection
public string IpAddress()
{
string strIp;
strIp = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIp == null)
{
strIp = Request.ServerVariables["REMOTE_ADDR"];
}
return strIp;
}
ASP.NET (VB.NET) without Proxy detection
Public Function IpAddress()
IpAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End Function
ASP.NET (VB.NET) with Proxy detection
Public Function IpAddress()
Dim strIp As String
strIp = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If strIp = "" Then
strIp = Request.ServerVariables("REMOTE_ADDR")
End If
IpAddress = strIp
End Function
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 INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
ipTO INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
countrySHORT CHAR(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 INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
--> ipTO INT(10) UNSIGNED ZEROFILL NOT NULL DEFAULT '0000000000',
--> countrySHORT CHAR(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\n';
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.
[ Back to Top ]a) Fill-up the online purchase form
https://www.regsoft.net/regsoft/vieworderpage.php3?currency=USD&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 are an existing subscriber of any IP2Location database, you can purchase an upgrade pack to download this database. With this upgrade pack, you just need to pay for the difference in price instead of full amount. Please proceed to this secure online form to order https://www.regsoft.net/purchase.php3?currency=USD&productid=57739 . Please remember to select the correct upgrade path before proceed.
[ Back to Top ]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 | 16403 |
AE | UNITED ARAB EMIRATES | 992185 |
AF | AFGHANISTAN | 29908 |
AG | ANTIGUA AND BARBUDA | 33424 |
AI | ANGUILLA | 7232 |
AL | ALBANIA | 29114 |
AM | ARMENIA | 90824 |
AN | NETHERLANDS ANTILLES | 55300 |
AO | ANGOLA | 9362 |
AQ | ANTARCTICA | 8202 |
AR | ARGENTINA | 1908501 |
AS | AMERICAN SAMOA | 6023 |
AT | AUSTRIA | 7403370 |
AU | AUSTRALIA | 27232937 |
AW | ARUBA | 29224 |
AZ | AZERBAIJAN | 99906 |
BA | BOSNIA AND HERZEGOVINA | 139235 |
BB | BARBADOS | 48452 |
BD | BANGLADESH | 225436 |
BE | BELGIUM | 6947314 |
BF | BURKINA FASO | 8704 |
BG | BULGARIA | 1556662 |
BH | BAHRAIN | 69410 |
BI | BURUNDI | 1217 |
BJ | BENIN | 5724 |
BM | BERMUDA | 115613 |
BN | BRUNEI DARUSSALAM | 172609 |
BO | BOLIVIA | 206575 |
BR | BRAZIL | 14138909 |
BS | BAHAMAS | 63165 |
BT | BHUTAN | 10240 |
BV | BOUVET ISLAND | 24 |
BW | BOTSWANA | 8954 |
BY | BELARUS | 126491 |
BZ | BELIZE | 100155 |
CA | CANADA | 67522335 |
CD | CONGO, THE DEMOCRATIC REPUBLIC OF THE | 4296 |
CF | CENTRAL AFRICAN REPUBLIC | 892 |
CG | CONGO | 2352 |
CH | SWITZERLAND | 18478234 |
CI | COTE D'IVOIRE | 39022 |
CK | COOK ISLANDS | 8232 |
CL | CHILE | 1920781 |
CM | CAMEROON | 17532 |
CN | CHINA | 72613075 |
CO | COLOMBIA | 869651 |
CR | COSTA RICA | 1208167 |
CS | SERBIA AND MONTENEGRO | 587098 |
CU | CUBA | 24710 |
CV | CAPE VERDE | 1792 |
CY | CYPRUS | 242122 |
CZ | CZECH REPUBLIC | 3727321 |
DE | GERMANY | 76325635 |
DJ | DJIBOUTI | 4688 |
DK | DENMARK | 7985775 |
DM | DOMINICA | 7259 |
DO | DOMINICAN REPUBLIC | 132883 |
DZ | ALGERIA | 104828 |
EC | ECUADOR | 235206 |
EE | ESTONIA | 651983 |
EG | EGYPT | 1245242 |
ER | ERITREA | 9824 |
ES | SPAIN | 18491808 |
ET | ETHIOPIA | 16712 |
FI | FINLAND | 11171440 |
FJ | FIJI | 103177 |
FK | FALKLAND ISLANDS (MALVINAS) | 256 |
FM | MICRONESIA, FEDERATED STATES OF | 1024 |
FO | FAROE ISLANDS | 20744 |
FR | FRANCE | 52415498 |
GA | GABON | 4194 |
GD | GRENADA | 4776 |
GE | GEORGIA | 133534 |
GF | FRENCH GUIANA | 512 |
GH | GHANA | 86812 |
GI | GIBRALTAR | 48284 |
GL | GREENLAND | 8192 |
GM | GAMBIA | 8200 |
GN | GUINEA | 68884 |
GP | GUADELOUPE | 4104 |
GQ | EQUATORIAL GUINEA | 796 |
GR | GREECE | 2577947 |
GT | GUATEMALA | 107364 |
GU | GUAM | 60416 |
GW | GUINEA-BISSAU | 912 |
GY | GUYANA | 7192 |
HK | HONG KONG | 6233906 |
HM | HEARD ISLAND AND MCDONALD ISLANDS | 48 |
HN | HONDURAS | 54416 |
HR | CROATIA | 412958 |
HT | HAITI | 42848 |
HU | HUNGARY | 2910936 |
ID | INDONESIA | 3147458 |
IE | IRELAND | 3903889 |
IL | ISRAEL | 4825418 |
IN | INDIA | 5988135 |
IO | BRITISH INDIAN OCEAN TERRITORY | 1024 |
IQ | IRAQ | 33445 |
IR | IRAN, ISLAMIC REPUBLIC OF | 888756 |
IS | ICELAND | 639961 |
IT | ITALY | 26507314 |
JM | JAMAICA | 78494 |
JO | JORDAN | 190064 |
JP | JAPAN | 141537740 |
KE | KENYA | 146522 |
KG | KYRGYZSTAN | 65840 |
KH | CAMBODIA | 35368 |
KI | KIRIBATI | 1024 |
KM | COMOROS | 456 |
KN | SAINT KITTS AND NEVIS | 8404 |
KP | KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF | 32 |
KR | KOREA, REPUBLIC OF | 39920004 |
KW | KUWAIT | 524010 |
KY | CAYMAN ISLANDS | 37624 |
KZ | KAZAKHSTAN | 274008 |
LA | LAO PEOPLE'S DEMOCRATIC REPUBLIC | 23848 |
LB | LEBANON | 131859 |
LC | SAINT LUCIA | 5704 |
LI | LIECHTENSTEIN | 50353 |
LK | SRI LANKA | 182206 |
LR | LIBERIA | 2310 |
LS | LESOTHO | 4360 |
LT | LITHUANIA | 838548 |
LU | LUXEMBOURG | 1074743 |
LV | LATVIA | 890196 |
LY | LIBYAN ARAB JAMAHIRIYA | 19740 |
MA | MOROCCO | 252378 |
MC | MONACO | 39329 |
MD | MOLDOVA, REPUBLIC OF | 87840 |
MG | MADAGASCAR | 13778 |
MH | MARSHALL ISLANDS | 792 |
MK | MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF | 144906 |
ML | MALI | 19128 |
MM | MYANMAR | 16384 |
MN | MONGOLIA | 46712 |
MO | MACAO | 146479 |
MP | NORTHERN MARIANA ISLANDS | 9216 |
MQ | MARTINIQUE | 5018 |
MR | MAURITANIA | 9921 |
MS | MONTSERRAT | 120 |
MT | MALTA | 235392 |
MU | MAURITIUS | 420644 |
MV | MALDIVES | 8304 |
MW | MALAWI | 9040 |
MX | MEXICO | 10390386 |
MY | MALAYSIA | 2631864 |
MZ | MOZAMBIQUE | 27427 |
NA | NAMIBIA | 19722 |
NC | NEW CALEDONIA | 38880 |
NE | NIGER | 2100 |
NG | NIGERIA | 234549 |
NI | NICARAGUA | 37656 |
NL | NETHERLANDS | 37263855 |
NO | NORWAY | 11734298 |
NP | NEPAL | 55004 |
NR | NAURU | 16696 |
NU | NIUE | 1024 |
NZ | NEW ZEALAND | 4336444 |
OM | OMAN | 239912 |
PA | PANAMA | 455608 |
PE | PERU | 682356 |
PF | FRENCH POLYNESIA | 18176 |
PG | PAPUA NEW GUINEA | 29452 |
PH | PHILIPPINES | 1278754 |
PK | PAKISTAN | 443830 |
PL | POLAND | 8009372 |
PR | PUERTO RICO | 295600 |
PT | PORTUGAL | 3007590 |
PW | PALAU | 5120 |
PY | PARAGUAY | 37512 |
QA | QATAR | 184817 |
RE | REUNION | 2054 |
RO | ROMANIA | 2824848 |
RU | RUSSIAN FEDERATION | 10887714 |
RW | RWANDA | 15656 |
SA | SAUDI ARABIA | 1096898 |
SB | SOLOMON ISLANDS | 8704 |
SC | SEYCHELLES | 5672 |
SD | SUDAN | 24600 |
SE | SWEDEN | 18904327 |
SG | SINGAPORE | 2730002 |
SI | SLOVENIA | 870074 |
SK | SLOVAKIA | 1429351 |
SL | SIERRA LEONE | 8233 |
SM | SAN MARINO | 9109 |
SN | SENEGAL | 25683 |
SO | SOMALIA | 2508 |
SR | SURINAME | 8393 |
ST | SAO TOME AND PRINCIPE | 664 |
SV | EL SALVADOR | 119592 |
SY | SYRIAN ARAB REPUBLIC | 29582 |
SZ | SWAZILAND | 3954 |
TC | TURKS AND CAICOS ISLANDS | 348 |
TD | CHAD | 624 |
TF | FRENCH SOUTHERN TERRITORIES | 256 |
TG | TOGO | 7968 |
TH | THAILAND | 2939045 |
TJ | TAJIKISTAN | 26756 |
TK | TOKELAU | 104 |
TL | TIMOR-LESTE | 1032 |
TM | TURKMENISTAN | 4608 |
TN | TUNISIA | 106652 |
TO | TONGA | 1280 |
TR | TURKEY | 4095153 |
TT | TRINIDAD AND TOBAGO | 49416 |
TV | TUVALU | 8192 |
TW | TAIWAN | 15239580 |
TZ | TANZANIA, UNITED REPUBLIC OF | 38493 |
UA | UKRAINE | 1428856 |
UG | UGANDA | 16904 |
UK | UNITED KINGDOM | 259058606 |
UM | UNITED STATES MINOR OUTLYING ISLANDS | 32 |
US | UNITED STATES | 1316319831 |
UY | URUGUAY | 43613523 |
UZ | UZBEKISTAN | 94880 |
VA | HOLY SEE (VATICAN CITY STATE) | 10496 |
VC | SAINT VINCENT AND THE GRENADINES | 3344 |
VE | VENEZUELA | 1406020 |
VG | VIRGIN ISLANDS, BRITISH | 7344 |
VI | VIRGIN ISLANDS, U.S. | 30920 |
VN | VIET NAM | 666475 |
VU | VANUATU | 4136 |
WS | SAMOA | 9210 |
YE | YEMEN | 20760 |
YT | MAYOTTE | 272 |
ZA | SOUTH AFRICA | 25347464 |
ZM | ZAMBIA | 10002 |
ZW | ZIMBABWE | 10447 |