Email: sales@ip2location.com
Web Site: http://www.ip2location.com
Copyright (c) 2001-2007 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 |
| 5 | Region |
| 6 | City |
| 7 | ISP |
For example:
"IPFROM","IPTO","COUNTRYSHORT","COUNTRYLONG","REGION","CITY","ISP"
"67297904","67297911","US","UNITED
STATES","MASSACHUSETTS","BEDFORD","PROGRESSSOFTWARECORP"
"67297912","67297919","US","UNITED STATES","TEXAS","FLOWER MOUND","B&TENTERPRISES"
"67297920","67297927","US","UNITED STATES","TENNESSEE","MEMPHIS","TRI-STATEBANKOFMEMPHIS"
| Column Number |
Column Descriptions |
Column Values |
| 1 | Beginning IP Number | 67297904 |
| 2 | Ending IP Number | 67297911 |
| 3 | ISO 3166 Country Code (2 Characters) | US |
| 4 | Full Country Name | UNITED STATES |
| 5 | Region | MASSACHUSETTS |
| 6 | City | BEDFORD |
| 7 | ISP | PROGRESSSOFTWARECORP |
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
Firstly, convert the IP address to IP number format (see question 3). Search the
IP-Country-Region-City-ISP database using IP number to match a record that has the IP Number between Beginning IP Number and Ending IP
Number.
For example, IP Address "4.2.226.113" is "67297905" in IP Number. It matched the following record in the database.
"67297904","67297911","US","UNITED STATES","MASSACHUSETTS","BEDFORD","PROGRESSSOFTWARECORP"
Therefore from the recordset, we know that the Country Name is "UNITED STATES", Country Code is "US", Region/State is "MASSACHUSETTS", City is "BEDFORD" and ISP is "PROGRESSSOFTWARECORP".
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], [REGION NAME COLUMN],
[CITY NAME COLUMN], [ISP NAME COLUMN] FROM [IP-COUNTRY-REGION-CITY-ISP
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].[IPCITYISP] (
[ipFROM] [float] NOT NULL ,
[ipTO] [float] NOT NULL ,
[countrySHORT] [nvarchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[countryLONG] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ipREGION] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ipCITY] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ipISP] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
MYSQL
CREATE TABLE IPCITYISP
(
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(64) NOT NULL,
ipREGION VARCHAR(128) NOT NULL,
ipCITY VARCHAR(128) NOT NULL,
ipISP VARCHAR(255) 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 'IPREGIONCITYISP' table
mysql> CREATE TABLE IPREGIONCITYISP
--> (
--> 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(64) NOT NULL,
--> ipREGION VARCHAR(128) NOT NULL,
--> ipCITY VARCHAR(128) NOT NULL,
--> ipISP VARCHAR(255) NOT NULL,
--> PRIMARY KEY(ipFROM, ipTO)
--> );
iii.Import the 'IPREGIONCITYISP.csv' database into table 'IPREGIONCITYISP'
mysql> LOAD DATA INFILE "<path>/IPREGIONCITYISP.csv" INTO TABLE
IPREGIONCITYISP FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
There are only 100 records in the demo version for evaluation purpose. The full version of database has more than 1,500,000 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/free.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 quarter. Our database is updated monthly to make sure it is always up-to-date and correct.
[ Back to Top ]a) Fill-up the online purchase form http://www.ip2location.net/Shoppingcart.aspx?productid=4&quantity=1.
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 ]A license is required for every physical server. Multiple licenses are available in bulk at discounted price.
| Number of License | Price |
| 1 | US$349 |
| 2 | US$599 |
| 5 | US$1199 |
| 10 | US$1999 |
| Corporate | US$3499 |
You can resell our databases provided you've purchased 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, single license cannot be sold to multiple parties.
[ Back to Top ]If you are an existing subscriber IP2Location, you can upgrade to higher package by paying the different in price. However, the subscription period will not be extended upon upgrade. Therefore it is recommended to upgrade as soon as you need additional information. To upgrade, please login to the customer area at http://www.ip2location.net/login.aspx and then click the upgrade button right beside the existing license.
[ Back to Top ]The database has over 95% of accuracy in country and ISP level, 70% in region level and 65% in city level, which is higher than any of our competitors. The country-level 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. The region-level and country-level inaccuracy is due to the flexibility given to each ISP to re-assign dynamic IP address within their service area.
| Country Code | Country Name | Number of IP Address |
| AD | ANDORRA | 16395 |
| AE | UNITED ARAB EMIRATES | 1276258 |
| AF | AFGHANISTAN | 32012 |
| AG | ANTIGUA AND BARBUDA | 32992 |
| AI | ANGUILLA | 8512 |
| AL | ALBANIA | 36846 |
| AM | ARMENIA | 94456 |
| AN | NETHERLANDS ANTILLES | 128164 |
| AO | ANGOLA | 34427 |
| AQ | ANTARCTICA | 8202 |
| AR | ARGENTINA | 3746829 |
| AS | AMERICAN SAMOA | 6289 |
| AT | AUSTRIA | 8274097 |
| AU | AUSTRALIA | 30591209 |
| AW | ARUBA | 32888 |
| AZ | AZERBAIJAN | 134468 |
| BA | BOSNIA AND HERZEGOVINA | 171331 |
| BB | BARBADOS | 60248 |
| BD | BANGLADESH | 323444 |
| BE | BELGIUM | 7896759 |
| BF | BURKINA FASO | 13368 |
| BG | BULGARIA | 2036684 |
| BH | BAHRAIN | 119630 |
| BI | BURUNDI | 3537 |
| BJ | BENIN | 7396 |
| BM | BERMUDA | 105501 |
| BN | BRUNEI DARUSSALAM | 172625 |
| BO | BOLIVIA | 314783 |
| BR | BRAZIL | 19297264 |
| BS | BAHAMAS | 84381 |
| BT | BHUTAN | 12288 |
| BV | BOUVET ISLAND | 184 |
| BW | BOTSWANA | 10102 |
| BY | BELARUS | 139055 |
| BZ | BELIZE | 114955 |
| CA | CANADA | 72083875 |
| CD | CONGO, THE DEMOCRATIC REPUBLIC OF THE | 6920 |
| CF | CENTRAL AFRICAN REPUBLIC | 2956 |
| CG | CONGO | 2895 |
| CH | SWITZERLAND | 18917504 |
| CI | COTE D'IVOIRE | 55461 |
| CK | COOK ISLANDS | 8232 |
| CL | CHILE | 3728877 |
| CM | CAMEROON | 44716 |
| CN | CHINA | 94202925 |
| CO | COLOMBIA | 1849042 |
| CR | COSTA RICA | 1294391 |
| CS | SERBIA AND MONTENEGRO | 758691 |
| CU | CUBA | 101110 |
| CV | CAPE VERDE | 2816 |
| CY | CYPRUS | 339254 |
| CZ | CZECH REPUBLIC | 5084253 |
| DE | GERMANY | 85516540 |
| DJ | DJIBOUTI | 4688 |
| DK | DENMARK | 8598489 |
| DM | DOMINICA | 8027 |
| DO | DOMINICAN REPUBLIC | 198155 |
| DZ | ALGERIA | 283856 |
| EC | ECUADOR | 439116 |
| EE | ESTONIA | 834627 |
| EG | EGYPT | 1376584 |
| ER | ERITREA | 5736 |
| ES | SPAIN | 20444757 |
| ET | ETHIOPIA | 16712 |
| FI | FINLAND | 12475788 |
| FJ | FIJI | 90633 |
| FK | FALKLAND ISLANDS (MALVINAS) | 896 |
| FM | MICRONESIA, FEDERATED STATES OF | 3072 |
| FO | FAROE ISLANDS | 33032 |
| FR | FRANCE | 67225510 |
| GA | GABON | 5258 |
| GD | GRENADA | 8008 |
| GE | GEORGIA | 198670 |
| GF | FRENCH GUIANA | 2560 |
| GH | GHANA | 108355 |
| GI | GIBRALTAR | 46616 |
| GL | GREENLAND | 16380 |
| GM | GAMBIA | 10287 |
| GN | GUINEA | 69304 |
| GP | GUADELOUPE | 4104 |
| GQ | EQUATORIAL GUINEA | 1456 |
| GR | GREECE | 3157844 |
| GS | SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS | 8 |
| GT | GUATEMALA | 249060 |
| GU | GUAM | 71688 |
| GW | GUINEA-BISSAU | 1920 |
| GY | GUYANA | 24168 |
| HK | HONG KONG | 6496313 |
| HM | HEARD ISLAND AND MCDONALD ISLANDS | 38 |
| HN | HONDURAS | 92852 |
| HR | CROATIA | 641303 |
| HT | HAITI | 70516 |
| HU | HUNGARY | 3606792 |
| ID | INDONESIA | 3438238 |
| IE | IRELAND | 4533605 |
| IL | ISRAEL | 5412214 |
| IN | INDIA | 7155669 |
| IO | BRITISH INDIAN OCEAN TERRITORY | 3072 |
| IQ | IRAQ | 75866 |
| IR | IRAN, ISLAMIC REPUBLIC OF | 1151614 |
| IS | ICELAND | 721925 |
| IT | ITALY | 29440961 |
| JE | JERSEY | 64 |
| JM | JAMAICA | 99310 |
| JO | JORDAN | 188710 |
| JP | JAPAN | 150528283 |
| KE | KENYA | 256162 |
| KG | KYRGYZSTAN | 87864 |
| KH | CAMBODIA | 47664 |
| KI | KIRIBATI | 3072 |
| KM | COMOROS | 456 |
| KN | SAINT KITTS AND NEVIS | 10108 |
| KP | KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF | 32 |
| KR | KOREA, REPUBLIC OF | 51037869 |
| KW | KUWAIT | 669809 |
| KY | CAYMAN ISLANDS | 28184 |
| KZ | KAZAKHSTAN | 367184 |
| LA | LAO PEOPLE'S DEMOCRATIC REPUBLIC | 22824 |
| LB | LEBANON | 162791 |
| LC | SAINT LUCIA | 5448 |
| LI | LIECHTENSTEIN | 69969 |
| LK | SRI LANKA | 233390 |
| LR | LIBERIA | 3797 |
| LS | LESOTHO | 4616 |
| LT | LITHUANIA | 1319788 |
| LU | LUXEMBOURG | 1047728 |
| LV | LATVIA | 1075852 |
| LY | LIBYAN ARAB JAMAHIRIYA | 36092 |
| MA | MOROCCO | 590058 |
| MC | MONACO | 56809 |
| MD | MOLDOVA, REPUBLIC OF | 168136 |
| MG | MADAGASCAR | 26602 |
| MH | MARSHALL ISLANDS | 792 |
| MK | MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF | 197658 |
| ML | MALI | 17848 |
| MM | MYANMAR | 12288 |
| MN | MONGOLIA | 80496 |
| MO | MACAO | 178207 |
| MP | NORTHERN MARIANA ISLANDS | 13312 |
| MQ | MARTINIQUE | 4794 |
| MR | MAURITANIA | 9929 |
| MS | MONTSERRAT | 632 |
| MT | MALTA | 223800 |
| MU | MAURITIUS | 30447060 |
| MV | MALDIVES | 18032 |
| MW | MALAWI | 10344 |
| MX | MEXICO | 15253915 |
| MY | MALAYSIA | 2862940 |
| MZ | MOZAMBIQUE | 40375 |
| NA | NAMIBIA | 50114 |
| NC | NEW CALEDONIA | 47072 |
| NE | NIGER | 2965 |
| NF | NORFOLK ISLAND | 1280 |
| NG | NIGERIA | 293985 |
| NI | NICARAGUA | 110824 |
| NL | NETHERLANDS | 38733494 |
| NO | NORWAY | 12513973 |
| NP | NEPAL | 51176 |
| NR | NAURU | 8512 |
| NU | NIUE | 1024 |
| NZ | NEW ZEALAND | 5059068 |
| OM | OMAN | 239912 |
| PA | PANAMA | 693832 |
| PE | PERU | 855686 |
| PF | FRENCH POLYNESIA | 42752 |
| PG | PAPUA NEW GUINEA | 26380 |
| PH | PHILIPPINES | 2137952 |
| PK | PAKISTAN | 529586 |
| PL | POLAND | 10297529 |
| PN | PITCAIRN | 8 |
| PR | PUERTO RICO | 546404 |
| PT | PORTUGAL | 3747455 |
| PW | PALAU | 5152 |
| PY | PARAGUAY | 66440 |
| QA | QATAR | 250433 |
| RE | REUNION | 2896 |
| RO | ROMANIA | 4614052 |
| RS | SERBIA | 7306 |
| RU | RUSSIAN FEDERATION | 13801582 |
| RW | RWANDA | 16688 |
| SA | SAUDI ARABIA | 1458375 |
| SB | SOLOMON ISLANDS | 8704 |
| SC | SEYCHELLES | 11120 |
| SD | SUDAN | 57384 |
| SE | SWEDEN | 21339212 |
| SG | SINGAPORE | 3131879 |
| SI | SLOVENIA | 1139973 |
| SK | SLOVAKIA | 1636464 |
| SL | SIERRA LEONE | 12241 |
| SM | SAN MARINO | 17813 |
| SN | SENEGAL | 43787 |
| SO | SOMALIA | 3772 |
| SR | SURINAME | 14529 |
| ST | SAO TOME AND PRINCIPE | 1176 |
| SV | EL SALVADOR | 261632 |
| SY | SYRIAN ARAB REPUBLIC | 87470 |
| SZ | SWAZILAND | 12858 |
| TC | TURKS AND CAICOS ISLANDS | 396 |
| TD | CHAD | 888 |
| TG | TOGO | 16168 |
| TH | THAILAND | 3350796 |
| TJ | TAJIKISTAN | 26756 |
| TK | TOKELAU | 136 |
| TL | TIMOR-LESTE | 1032 |
| TM | TURKMENISTAN | 4608 |
| TN | TUNISIA | 106652 |
| TO | TONGA | 4352 |
| TR | TURKEY | 6281357 |
| TT | TRINIDAD AND TOBAGO | 153168 |
| TV | TUVALU | 8192 |
| TW | TAIWAN | 17662528 |
| TZ | TANZANIA, UNITED REPUBLIC OF | 81704 |
| UA | UKRAINE | 1820526 |
| UG | UGANDA | 88872 |
| UK | UNITED KINGDOM | 255070793 |
| UM | UNITED STATES MINOR OUTLYING ISLANDS | 90 |
| US | UNITED STATES | 1361150543 |
| UY | URUGUAY | 296488 |
| UZ | UZBEKISTAN | 127040 |
| VA | HOLY SEE (VATICAN CITY STATE) | 10496 |
| VC | SAINT VINCENT AND THE GRENADINES | 5648 |
| VE | VENEZUELA | 2213216 |
| VG | VIRGIN ISLANDS, BRITISH | 9268 |
| VI | VIRGIN ISLANDS, U.S. | 95626 |
| VN | VIET NAM | 831355 |
| VU | VANUATU | 4156 |
| WS | SAMOA | 9210 |
| YE | YEMEN | 28952 |
| YT | MAYOTTE | 272 |
| ZA | SOUTH AFRICA | 7312920 |
| ZM | ZAMBIA | 21666 |
| ZW | ZIMBABWE | 37743 |