IP2Location™ IP-Country Database FAQ

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

Copyright (c) 2003 by Hexa Software Development Center


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 IP-COUNTRY database to IP-COUNTRY-ISP 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);
    }
}

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

 

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

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

[ 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. We will give you free one year update if you purchase the database now.

[ 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?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 IP-COUNTRY database to IP-COUNTRY-ISP database?

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

[ 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
ADANDORRA8195
AEUNITED ARAB EMIRATES418813
AFAFGHANISTAN4152
AGANTIGUA AND BARBUDA24213
AIANGUILLA1344
ALALBANIA15624
AMARMENIA43960
ANNETHERLANDS ANTILLES24206
AOANGOLA20306
APASIA PACIFIC36752
AQANTARCTICA512
ARARGENTINA1432200
ASAMERICAN SAMOA2304
ATAUSTRIA6122485
AUAUSTRALIA21875117
AWARUBA5376
AZAZERBAIJAN51336
BABOSNIA AND HERZEGOWINA80460
BBBARBADOS29600
BDBANGLADESH179948
BEBELGIUM5792042
BFBURKINA FASO10240
BGBULGARIA725645
BHBAHRAIN21114
BIBURUNDI1040
BJBENIN6464
BMBERMUDA62989
BNBRUNEI DARUSSALAM33793
BOBOLIVIA82096
BRBRAZIL10763563
BSBAHAMAS34224
BTBHUTAN8192
BVBOUVET ISLAND1312
BWBOTSWANA6560
BYBELARUS76769
BZBELIZE13456
CACANADA48907353
CDCONGO, THE DEMOCRATIC REPUBLIC OF THE1520
CFCENTRAL AFRICAN REPUBLIC564
CGCONGO1304
CHSWITZERLAND13125987
CICOTE D'IVOIRE20430
CKCOOK ISLANDS8208
CLCHILE1806733
CMCAMEROON13480
CNCHINA37007177
COCOLOMBIA539449
CRCOSTA RICA122288
CSCZECHOSLOVAKIA (FORMER)32552
CUCUBA22094
CVCAPE VERDE1024
CYCYPRUS129037
CZCZECH REPUBLIC2683561
DEGERMANY64163716
DJDJIBOUTI296
DKDENMARK5220717
DMDOMINICA6456
DODOMINICAN REPUBLIC65113
DZALGERIA78248
ECECUADOR180225
EEESTONIA395330
EGEGYPT912942
ERERITREA1680
ESSPAIN10273735
ETETHIOPIA16640
EUEUROPEAN UNION37434937
FIFINLAND8873597
FJFIJI84480
FKFALKLAND ISLANDS (MALVINAS)256
FMMICRONESIA, FEDERATED STATES OF768
FOFAROE ISLANDS16776
FRFRANCE56732029
FXFRANCE, METROPOLITAN16
GAGABON7696
GBGREAT BRITAIN7168
GDGRENADA5960
GEGEORGIA132424
GHGHANA46040
GIGIBRALTAR33300
GLGREENLAND8448
GMGAMBIA8192
GNGUINEA71848
GPGUADELOUPE2376
GQEQUATORIAL GUINEA188
GRGREECE2194018
GTGUATEMALA42852
GUGUAM126544
GWGUINEA-BISSAU912
GYGUYANA8360
HKHONG KONG5451955
HMHEARD ISLAND AND MCDONALD ISLANDS18
HNHONDURAS25916
HRCROATIA293342
HTHAITI40384
HUHUNGARY2029083
IDINDONESIA1395508
IEIRELAND1746877
ILISRAEL3607933
ININDIA3051068
IOBRITISH INDIAN OCEAN TERRITORY4096
IQIRAQ96
IRIRAN, ISLAMIC REPUBLIC OF657434
ISICELAND488518
ITITALY22063551
JMJAMAICA53833
JOJORDAN138208
JPJAPAN87931785
KEKENYA96985
KGKYRGYZSTAN49664
KHCAMBODIA24832
KIKIRIBATI1024
KMCOMOROS192
KNSAINT KITTS AND NEVIS4504
KPKOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF96
KRKOREA, REPUBLIC OF29374217
KWKUWAIT465607
KYCAYMAN ISLANDS6296
KZKAZAKSTAN172910
LALAO PEOPLE'S DEMOCRATIC REPUBLIC26128
LBLEBANON81425
LCSAINT LUCIA2224
LILIECHTENSTEIN26341
LKSRI LANKA163344
LRLIBERIA1920
LSLESOTHO5152
LTLITHUANIA400515
LULUXEMBOURG786338
LVLATVIA487840
LYLIBYAN ARAB JAMAHIRIYA18704
MAMOROCCO158696
MCMONACO31586
MDMOLDOVA, REPUBLIC OF59992
MGMADAGASCAR9988
MHMARSHALL ISLANDS328
MKMACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF123920
MLMALI6800
MMMYANMAR16640
MNMONGOLIA58120
MOMACAU63781
MPNORTHERN MARIANA ISLANDS9584
MQMARTINIQUE3912
MRMAURITANIA11449
MSMONTSERRAT272
MTMALTA195880
MUMAURITIUS19988
MVMALDIVES12288
MWMALAWI5376
MXMEXICO4806994
MYMALAYSIA1837160
MZMOZAMBIQUE23987
NANAMIBIA28390
NCNEW CALEDONIA26152
NENIGER3350
NGNIGERIA173152
NINICARAGUA24680
NLNETHERLANDS30318053
NONORWAY8703134
NPNEPAL60874
NRNAURU8224
NZNEW ZEALAND3788384
OMOMAN166680
PAPANAMA201666
PEPERU391382
PFFRENCH POLYNESIA10000
PGPAPUA NEW GUINEA37636
PHPHILIPPINES953945
PKPAKISTAN317698
PLPOLAND4492521
PRPUERTO RICO146125
PSPALESTINIAN TERRITORY, OCCUPIED59283
PTPORTUGAL1789528
PWPALAU8704
PYPARAGUAY21336
QAQATAR29953
REREUNION6
ROROMANIA1195680
RURUSSIAN FEDERATION7211276
RWRWANDA6384
SASAUDI ARABIA635278
SBSOLOMON ISLANDS8704
SCSEYCHELLES1024
SDSUDAN10240
SESWEDEN14778929
SGSINGAPORE2204718
SISLOVENIA632282
SKSLOVAKIA890782
SLSIERRA LEONE5857
SMSAN MARINO8581
SNSENEGAL14824
SOSOMALIA1228
SRSURINAME1856
STSAO TOME AND PRINCIPE512
SVEL SALVADOR38847
SYSYRIAN ARAB REPUBLIC34752
SZSWAZILAND14672
TCTURKS AND CAICOS ISLANDS1920
TDCHAD308
TFFRENCH SOUTHERN TERRITORIES256
TGTOGO8992
THTHAILAND1939075
TJTAJIKISTAN4704
TKTOKELAU16
TMTURKMENISTAN5632
TNTUNISIA41488
TOTONGA5376
TPEAST TIMOR1280
TRTURKEY2639957
TTTRINIDAD AND TOBAGO30240
TVTUVALU8448
TWTAIWAN, PROVINCE OF CHINA12835040
TZTANZANIA, UNITED REPUBLIC OF24764
UAUKRAINE989935
UGUGANDA16536
UKUNITED KINGDOM83690976
UMUNITED STATES MINOR OUTLYING ISLANDS88
USUNITED STATES550596534
UYURUGUAY168649
UZUZBEKISTAN34232
VAHOLY SEE (VATICAN CITY STATE)11008
VCSAINT VINCENT AND THE GRENADINES640
VEVENEZUELA1038549
VGVIRGIN ISLANDS, BRITISH12841
VIVIRGIN ISLANDS, U.S.10432
VNVIET NAM160880
VUVANUATU8192
WSSAMOA10752
YEYEMEN9480
YUSERBIA AND MONTENEGRO516704
ZASOUTH AFRICA6404353
ZMZAMBIA11906
ZWZIMBABWE27951

Data Source: IP2Location™ IP-COUNTRY-REGION-CITY-ISP [DB4] October 2003 Edition Database

[ Back to Top ]


Please contact us if you have any further question.

Hexa Software Development Center
3D-27-04, Jalan Batu Uban, Gelugor, 11700 Pulau Pinang, Malaysia.
sales@ip2location.com

IP2Location™ is a trademark of Hexa Software Development Center.

Copyright © 2003 Hexa Software Development Center. All rights reserved.
Revised: 09/25/03.