IP2Location™ IP-Country Database FAQ

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

Copyright (c) 2002-2005 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 Name and Country Code 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 this package to other 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

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

[ 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 Name and Country Code from the IP Number?

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.
 

[ 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] FROM [IP-COUNTRY 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].[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.

[ 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 '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.

[ Back to Top ]

9. How many records are in this demo version?

There are only 100 records in the demo version. The full version of database has more than 55000 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/test/ipcountry.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 year. Our database is updated monthly to make sure it is always correct.

[ Back to Top ]

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

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.

[ 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?
 

Number of License Price
1 US$49
2 US$89
5 US$179
10 US$299
Corporate US$499

[ Back to Top ]

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

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 ]

16. How do I upgrade from this package to other database?

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 ]

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

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 CodeCountry NameNumber of IP Address
ADANDORRA16403
AEUNITED ARAB EMIRATES992185
AFAFGHANISTAN29908
AGANTIGUA AND BARBUDA33424
AIANGUILLA7232
ALALBANIA29114
AMARMENIA90824
ANNETHERLANDS ANTILLES55300
AOANGOLA9362
AQANTARCTICA8202
ARARGENTINA1908501
ASAMERICAN SAMOA6023
ATAUSTRIA7403370
AUAUSTRALIA27232937
AWARUBA29224
AZAZERBAIJAN99906
BABOSNIA AND HERZEGOVINA139235
BBBARBADOS48452
BDBANGLADESH225436
BEBELGIUM6947314
BFBURKINA FASO8704
BGBULGARIA1556662
BHBAHRAIN69410
BIBURUNDI1217
BJBENIN5724
BMBERMUDA115613
BNBRUNEI DARUSSALAM172609
BOBOLIVIA206575
BRBRAZIL14138909
BSBAHAMAS63165
BTBHUTAN10240
BVBOUVET ISLAND24
BWBOTSWANA8954
BYBELARUS126491
BZBELIZE100155
CACANADA67522335
CDCONGO, THE DEMOCRATIC REPUBLIC OF THE4296
CFCENTRAL AFRICAN REPUBLIC892
CGCONGO2352
CHSWITZERLAND18478234
CICOTE D'IVOIRE39022
CKCOOK ISLANDS8232
CLCHILE1920781
CMCAMEROON17532
CNCHINA72613075
COCOLOMBIA869651
CRCOSTA RICA1208167
CSSERBIA AND MONTENEGRO587098
CUCUBA24710
CVCAPE VERDE1792
CYCYPRUS242122
CZCZECH REPUBLIC3727321
DEGERMANY76325635
DJDJIBOUTI4688
DKDENMARK7985775
DMDOMINICA7259
DODOMINICAN REPUBLIC132883
DZALGERIA104828
ECECUADOR235206
EEESTONIA651983
EGEGYPT1245242
ERERITREA9824
ESSPAIN18491808
ETETHIOPIA16712
FIFINLAND11171440
FJFIJI103177
FKFALKLAND ISLANDS (MALVINAS)256
FMMICRONESIA, FEDERATED STATES OF1024
FOFAROE ISLANDS20744
FRFRANCE52415498
GAGABON4194
GDGRENADA4776
GEGEORGIA133534
GFFRENCH GUIANA512
GHGHANA86812
GIGIBRALTAR48284
GLGREENLAND8192
GMGAMBIA8200
GNGUINEA68884
GPGUADELOUPE4104
GQEQUATORIAL GUINEA796
GRGREECE2577947
GTGUATEMALA107364
GUGUAM60416
GWGUINEA-BISSAU912
GYGUYANA7192
HKHONG KONG6233906
HMHEARD ISLAND AND MCDONALD ISLANDS48
HNHONDURAS54416
HRCROATIA412958
HTHAITI42848
HUHUNGARY2910936
IDINDONESIA3147458
IEIRELAND3903889
ILISRAEL4825418
ININDIA5988135
IOBRITISH INDIAN OCEAN TERRITORY1024
IQIRAQ33445
IRIRAN, ISLAMIC REPUBLIC OF888756
ISICELAND639961
ITITALY26507314
JMJAMAICA78494
JOJORDAN190064
JPJAPAN141537740
KEKENYA146522
KGKYRGYZSTAN65840
KHCAMBODIA35368
KIKIRIBATI1024
KMCOMOROS456
KNSAINT KITTS AND NEVIS8404
KPKOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF32
KRKOREA, REPUBLIC OF39920004
KWKUWAIT524010
KYCAYMAN ISLANDS37624
KZKAZAKHSTAN274008
LALAO PEOPLE'S DEMOCRATIC REPUBLIC23848
LBLEBANON131859
LCSAINT LUCIA5704
LILIECHTENSTEIN50353
LKSRI LANKA182206
LRLIBERIA2310
LSLESOTHO4360
LTLITHUANIA838548
LULUXEMBOURG1074743
LVLATVIA890196
LYLIBYAN ARAB JAMAHIRIYA19740
MAMOROCCO252378
MCMONACO39329
MDMOLDOVA, REPUBLIC OF87840
MGMADAGASCAR13778
MHMARSHALL ISLANDS792
MKMACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF144906
MLMALI19128
MMMYANMAR16384
MNMONGOLIA46712
MOMACAO146479
MPNORTHERN MARIANA ISLANDS9216
MQMARTINIQUE5018
MRMAURITANIA9921
MSMONTSERRAT120
MTMALTA235392
MUMAURITIUS420644
MVMALDIVES8304
MWMALAWI9040
MXMEXICO10390386
MYMALAYSIA2631864
MZMOZAMBIQUE27427
NANAMIBIA19722
NCNEW CALEDONIA38880
NENIGER2100
NGNIGERIA234549
NINICARAGUA37656
NLNETHERLANDS37263855
NONORWAY11734298
NPNEPAL55004
NRNAURU16696
NUNIUE1024
NZNEW ZEALAND4336444
OMOMAN239912
PAPANAMA455608
PEPERU682356
PFFRENCH POLYNESIA18176
PGPAPUA NEW GUINEA29452
PHPHILIPPINES1278754
PKPAKISTAN443830
PLPOLAND8009372
PRPUERTO RICO295600
PTPORTUGAL3007590
PWPALAU5120
PYPARAGUAY37512
QAQATAR184817
REREUNION2054
ROROMANIA2824848
RURUSSIAN FEDERATION10887714
RWRWANDA15656
SASAUDI ARABIA1096898
SBSOLOMON ISLANDS8704
SCSEYCHELLES5672
SDSUDAN24600
SESWEDEN18904327
SGSINGAPORE2730002
SISLOVENIA870074
SKSLOVAKIA1429351
SLSIERRA LEONE8233
SMSAN MARINO9109
SNSENEGAL25683
SOSOMALIA2508
SRSURINAME8393
STSAO TOME AND PRINCIPE664
SVEL SALVADOR119592
SYSYRIAN ARAB REPUBLIC29582
SZSWAZILAND3954
TCTURKS AND CAICOS ISLANDS348
TDCHAD624
TFFRENCH SOUTHERN TERRITORIES256
TGTOGO7968
THTHAILAND2939045
TJTAJIKISTAN26756
TKTOKELAU104
TLTIMOR-LESTE1032
TMTURKMENISTAN4608
TNTUNISIA106652
TOTONGA1280
TRTURKEY4095153
TTTRINIDAD AND TOBAGO49416
TVTUVALU8192
TWTAIWAN15239580
TZTANZANIA, UNITED REPUBLIC OF38493
UAUKRAINE1428856
UGUGANDA16904
UKUNITED KINGDOM259058606
UMUNITED STATES MINOR OUTLYING ISLANDS32
USUNITED STATES1316319831
UYURUGUAY43613523
UZUZBEKISTAN94880
VAHOLY SEE (VATICAN CITY STATE)10496
VCSAINT VINCENT AND THE GRENADINES3344
VEVENEZUELA1406020
VGVIRGIN ISLANDS, BRITISH7344
VIVIRGIN ISLANDS, U.S.30920
VNVIET NAM666475
VUVANUATU4136
WSSAMOA9210
YEYEMEN20760
YTMAYOTTE272
ZASOUTH AFRICA25347464
ZMZAMBIA10002
ZWZIMBABWE10447

Data Source: IP2Location™ IP-COUNTRY [DB1] October 2005 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 © 2002-2005 IP2Location.com. All rights reserved.
Revised: 09/22/05.