IP2Location™ IP-Country-Region-City Database FAQ

Email: sales@ip2location.com
Web Site: http://www.ip2location.com

Copyright (c) 2001-2007 by IP2Location.com


Table of Contents

  1. What is the database format?
  2. What is the definition of each column in the table?
  3. How do I convert a IP Address to a IP Number?
  4. How do I retrieve the Country/Region/City name from the IP Number?
  5. How do I use this database?
  6. How do I retrieve visitor's IP address using ASP, PHP, JSP & ColdFusion?
  7. How do I create the SQL table?
  8. How do I create and import the database into MySQL database?
  9. How many records are in this demo version?
  10. Where can I test the demo version for free?
  11. Why do we update this database periodically?
  12. I want to download the full version. What should I do now?
  13. What do I get if I purchase the full version?
  14. How much is the cost of database license for multiple servers?
  15. Can I resell or reuse the database in my client application?
  16. How do I upgrade from other package to IP-COUNTRY-REGION-CITY database?
  17. How many countries are included in the database? What is the accuracy?

1. What is the database format?

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 ]

2. What is the definition of each column in the table?

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

For example:
"IPFROM","IPTO","COUNTRYSHORT","COUNTRYLONG","REGION","CITY","ISP"
"67297904","67297911","US","UNITED STATES","MASSACHUSETTS","BEDFORD","PROGRESS SOFTWARE CORP"
"67297912","67297919","US","UNITED STATES","TEXAS","FLOWER MOUND","B&TENTERPRISES"
"67297920","67297927","US","UNITED STATES","TENNESSEE","MEMPHIS","TRI-STATE BANK OF MEMPHIS"

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

[ Back to Top ]

3. How do I convert a IP Address to a IP Number?

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

[ Back to Top ]

4. How do I retrieve the Country/Region/City name from the IP Number?

Firstly, convert the IP address to IP number format (see question 3). Search the IP-Country-Region-City 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"

Therefore from the recordset, we know that the Country Name is "UNITED STATES", Country Code is "US", Region/State is "MASSACHUSETTS" and City is "BEDFORD".

[ Back to Top ]

5. How do I use this database?

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] FROM [IP-COUNTRY-REGION-CITY TABLE] WHERE
[SEARCH IP NO] BETWEEN [IP FROM COLUMN] AND [IP TO COLUMN]

 

[ Back to Top ]

6. How do I retrieve visitor's IP address using ASP, PHP, JSP & ColdFusion?

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

[ Back to Top ]

7. How do I create the SQL table?

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
) 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,
    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.

[ Back to Top ]

8. How do I create and import the database into MySQL database?

i. Create and connect to 'ip2Location' database
mysql> CREATE DATABASE ip2location
mysql> CONNECT ip2location

ii. Create 'IPREGIONCITY' table
mysql> CREATE TABLE IPREGIONCITY
    --> (
    --> 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,
    --> PRIMARY KEY(ipFROM, ipTO)
    --> );

iii.Import the 'IPREGIONCITY.csv' database into table 'IPREGIONCITY'
mysql> LOAD DATA INFILE "<path>/IPREGIONCITY.csv" INTO TABLE IPREGIONCITY FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';

[ Back to Top ]

9. How many records are available in this demo version?

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 ]

10. Where can I test the demo version for free?

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 ]

11. Why do we need to update this database periodically?

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 ]

12. I want to download the full version. What should I do now?

a) Fill-up the online purchase form http://www.ip2location.net/Shoppingcart.aspx?productid=3&quantity=1.
b) We will generate an unique login/password to allow you downloading the database for one year after we received your order.

[ Back to Top ]

13. What do I get if I purchase the full version?

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 ]

14. How much is the cost of database license for multiple servers?

A license is required for every physical server. Multiple licenses are available in bulk at discounted price.

Number of License Price
1 US$199
2 US$349
5 US$699
10 US$1299
Corporate US$1999

[ Back to Top ]

15. Can I resell or reuse the database in my client application?

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 ]

16. How do I upgrade from other package to IP-COUNTRY-REGION-CITY database?

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 ]

17. How many countries are included in the database? What is the accuracy?

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 CodeCountry NameNumber of IP Address
ADANDORRA16395
AEUNITED ARAB EMIRATES1276258
AFAFGHANISTAN32012
AGANTIGUA AND BARBUDA32992
AIANGUILLA8512
ALALBANIA36846
AMARMENIA94456
ANNETHERLANDS ANTILLES128164
AOANGOLA34427
AQANTARCTICA8202
ARARGENTINA3746829
ASAMERICAN SAMOA6289
ATAUSTRIA8274097
AUAUSTRALIA30591209
AWARUBA32888
AZAZERBAIJAN134468
BABOSNIA AND HERZEGOVINA171331
BBBARBADOS60248
BDBANGLADESH323444
BEBELGIUM7896759
BFBURKINA FASO13368
BGBULGARIA2036684
BHBAHRAIN119630
BIBURUNDI3537
BJBENIN7396
BMBERMUDA105501
BNBRUNEI DARUSSALAM172625
BOBOLIVIA314783
BRBRAZIL19297264
BSBAHAMAS84381
BTBHUTAN12288
BVBOUVET ISLAND184
BWBOTSWANA10102
BYBELARUS139055
BZBELIZE114955
CACANADA72083875
CDCONGO, THE DEMOCRATIC REPUBLIC OF THE6920
CFCENTRAL AFRICAN REPUBLIC2956
CGCONGO2895
CHSWITZERLAND18917504
CICOTE D'IVOIRE55461
CKCOOK ISLANDS8232
CLCHILE3728877
CMCAMEROON44716
CNCHINA94202925
COCOLOMBIA1849042
CRCOSTA RICA1294391
CSSERBIA AND MONTENEGRO758691
CUCUBA101110
CVCAPE VERDE2816
CYCYPRUS339254
CZCZECH REPUBLIC5084253
DEGERMANY85516540
DJDJIBOUTI4688
DKDENMARK8598489
DMDOMINICA8027
DODOMINICAN REPUBLIC198155
DZALGERIA283856
ECECUADOR439116
EEESTONIA834627
EGEGYPT1376584
ERERITREA5736
ESSPAIN20444757
ETETHIOPIA16712
FIFINLAND12475788
FJFIJI90633
FKFALKLAND ISLANDS (MALVINAS)896
FMMICRONESIA, FEDERATED STATES OF3072
FOFAROE ISLANDS33032
FRFRANCE67225510
GAGABON5258
GDGRENADA8008
GEGEORGIA198670
GFFRENCH GUIANA2560
GHGHANA108355
GIGIBRALTAR46616
GLGREENLAND16380
GMGAMBIA10287
GNGUINEA69304
GPGUADELOUPE4104
GQEQUATORIAL GUINEA1456
GRGREECE3157844
GSSOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS8
GTGUATEMALA249060
GUGUAM71688
GWGUINEA-BISSAU1920
GYGUYANA24168
HKHONG KONG6496313
HMHEARD ISLAND AND MCDONALD ISLANDS38
HNHONDURAS92852
HRCROATIA641303
HTHAITI70516
HUHUNGARY3606792
IDINDONESIA3438238
IEIRELAND4533605
ILISRAEL5412214
ININDIA7155669
IOBRITISH INDIAN OCEAN TERRITORY3072
IQIRAQ75866
IRIRAN, ISLAMIC REPUBLIC OF1151614
ISICELAND721925
ITITALY29440961
JEJERSEY64
JMJAMAICA99310
JOJORDAN188710
JPJAPAN150528283
KEKENYA256162
KGKYRGYZSTAN87864
KHCAMBODIA47664
KIKIRIBATI3072
KMCOMOROS456
KNSAINT KITTS AND NEVIS10108
KPKOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF32
KRKOREA, REPUBLIC OF51037869
KWKUWAIT669809
KYCAYMAN ISLANDS28184
KZKAZAKHSTAN367184
LALAO PEOPLE'S DEMOCRATIC REPUBLIC22824
LBLEBANON162791
LCSAINT LUCIA5448
LILIECHTENSTEIN69969
LKSRI LANKA233390
LRLIBERIA3797
LSLESOTHO4616
LTLITHUANIA1319788
LULUXEMBOURG1047728
LVLATVIA1075852
LYLIBYAN ARAB JAMAHIRIYA36092
MAMOROCCO590058
MCMONACO56809
MDMOLDOVA, REPUBLIC OF168136
MGMADAGASCAR26602
MHMARSHALL ISLANDS792
MKMACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF197658
MLMALI17848
MMMYANMAR12288
MNMONGOLIA80496
MOMACAO178207
MPNORTHERN MARIANA ISLANDS13312
MQMARTINIQUE4794
MRMAURITANIA9929
MSMONTSERRAT632
MTMALTA223800
MUMAURITIUS30447060
MVMALDIVES18032
MWMALAWI10344
MXMEXICO15253915
MYMALAYSIA2862940
MZMOZAMBIQUE40375
NANAMIBIA50114
NCNEW CALEDONIA47072
NENIGER2965
NFNORFOLK ISLAND1280
NGNIGERIA293985
NINICARAGUA110824
NLNETHERLANDS38733494
NONORWAY12513973
NPNEPAL51176
NRNAURU8512
NUNIUE1024
NZNEW ZEALAND5059068
OMOMAN239912
PAPANAMA693832
PEPERU855686
PFFRENCH POLYNESIA42752
PGPAPUA NEW GUINEA26380
PHPHILIPPINES2137952
PKPAKISTAN529586
PLPOLAND10297529
PNPITCAIRN8
PRPUERTO RICO546404
PTPORTUGAL3747455
PWPALAU5152
PYPARAGUAY66440
QAQATAR250433
REREUNION2896
ROROMANIA4614052
RSSERBIA7306
RURUSSIAN FEDERATION13801582
RWRWANDA16688
SASAUDI ARABIA1458375
SBSOLOMON ISLANDS8704
SCSEYCHELLES11120
SDSUDAN57384
SESWEDEN21339212
SGSINGAPORE3131879
SISLOVENIA1139973
SKSLOVAKIA1636464
SLSIERRA LEONE12241
SMSAN MARINO17813
SNSENEGAL43787
SOSOMALIA3772
SRSURINAME14529
STSAO TOME AND PRINCIPE1176
SVEL SALVADOR261632
SYSYRIAN ARAB REPUBLIC87470
SZSWAZILAND12858
TCTURKS AND CAICOS ISLANDS396
TDCHAD888
TGTOGO16168
THTHAILAND3350796
TJTAJIKISTAN26756
TKTOKELAU136
TLTIMOR-LESTE1032
TMTURKMENISTAN4608
TNTUNISIA106652
TOTONGA4352
TRTURKEY6281357
TTTRINIDAD AND TOBAGO153168
TVTUVALU8192
TWTAIWAN17662528
TZTANZANIA, UNITED REPUBLIC OF81704
UAUKRAINE1820526
UGUGANDA88872
UKUNITED KINGDOM255070793
UMUNITED STATES MINOR OUTLYING ISLANDS90
USUNITED STATES1361150543
UYURUGUAY296488
UZUZBEKISTAN127040
VAHOLY SEE (VATICAN CITY STATE)10496
VCSAINT VINCENT AND THE GRENADINES5648
VEVENEZUELA2213216
VGVIRGIN ISLANDS, BRITISH9268
VIVIRGIN ISLANDS, U.S.95626
VNVIET NAM831355
VUVANUATU4156
WSSAMOA9210
YEYEMEN28952
YTMAYOTTE272
ZASOUTH AFRICA7312920
ZMZAMBIA21666
ZWZIMBABWE37743

Data Source: IP2Location™ IP-COUNTRY [DB1] December 2006 Edition Database

[ Back to Top ]


Please contact us if you have any further question.

IP2Location.com
1-2-15, Mayang Mall Complex, Jalan Mayang Pasir 1, 11950 Bandar Bayan Baru, Pulau Pinang, Malaysia.
sales@ip2location.com

IP2Location™ is a trademark of Hexasoft Development Sdn. Bhd.

Copyright © 2001-2007 IP2Location.com. All rights reserved.
Revised: 11/18/06.