FAQs

We provide two different database formats (CSV and BIN).

The first database format is known as Comma Separated Values (CSV). It is a text file and all fields are separated by a comma with double quote in each field. Each individual row is a database record.

The second database format is known as Binary (BIN). It is a binary file with database information. Developers access to the BIN files using IP2Location API available in multiple languages.

You can automate the IP2Location LITE database using download client or common HTTP applications such as wget or curl. We update IP2Location databases on the first day of the calendar month. Please download the database once a month during a random day from the first week of calendar month to avoid network congestion. We will disable any LITE account if account sharing or massive download is detected.

./download.pl -package DB11LITE -login mylogin -password mypassword

Package Code Description
DB11LITE IP2Location LITE DB11 - IPV4 - CSV
DB11LITEBIN IP2Location LITE DB11 - IPV4 - BIN
DB11LITE IP2Location LITE DB11 - IPV6 - CSV
DB11LITEBINIPV6 IP2Location LITE DB11 - IPV6 - BIN

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 more efficient to search between a range of numbers in a database.

The Beginning IP number and Ending IP Number are calculated based on the following formula:

IP Number = 16777216*w + 65536*x + 256*y + z     (1)

where

IP Address = w.x.y.z


For example, if the IP address is "202.186.13.4", then its IP Number will be "3401190660", 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 modulus operator and
int
returns the integer part of the division.
					
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
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);
    }
}
long Dot2LongIP(String ipstring) {
	String[] ipAddressInArray = ipstring.split("\.");
	long result = 0;
	long ip = 0;
	for (int x = 3; x >= 0; x--) {
		ip = Long.parseLong(ipAddressInArray[3 - x]);
		result |= ip << (x << 3);
	}
	return result;
}
function Dot2LongIP(ipAddress)
{
  if(arguments.ipAddress EQ "")
  {
	return 0;
  }
  else
  {
	ips = ListToArray( arguments.ipAddress, "." );
	return( ( 16777216 * ips[1] ) + ( 65536 * ips[2] ) + ( 256 * ips[3] ) + ips[4] );
  }
}
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;
    }
}
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
use Socket;

sub dot2LongIP {
	my $ip_address = shift(@_);
	return unpack("N",inet_aton($ip_address));
}
require 'ipaddr'

def dot2LongIP(ip) 
	ipnum = IPAddr.new(ip)
	return ipnum.to_i
end
import ipaddress

def dot2LongIP(ip):
	return int(ipaddress.IPv4Address(ip))
uint32_t Dot2LongIP(char* ipstring)
{
	uint32_t ip = inet_addr(ipstring);
	uint8_t *ptr = (uint8_t *) &ip;
	uint32_t a = 0;
	
	if (ipstring != NULL) {
		a =  (uint8_t)(ptr[3]);
		a += (uint8_t)(ptr[2]) * 256;
		a += (uint8_t)(ptr[1]) * 256 * 256;
		a += (uint8_t)(ptr[0]) * 256 * 256 * 256;
	}
	return a;
}
CREATE FUNCTION Dot2LongIP (ip text)
RETURNS bigint
BEGIN
	DECLARE ipnum bigint;
	SET ipnum = (SELECT INET_ATON(ip));
	RETURN ipnum;
END
Create FUNCTION [dbo].[Dot2LongIP]( @IP VarChar(15) )
RETURNS BigInt
AS
BEGIN
   DECLARE @ipA BigInt,
         @ipB Int,
         @ipC Int,
         @ipD Int,
         @ipI BigInt
   SELECT @ipA = LEFT(@ip, PATINDEX('%.%', @ip) - 1 )
   SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipA) - 1 )

   SELECT @ipB = LEFT(@ip, PATINDEX('%.%', @ip) - 1 )
   SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipB) - 1 )

   SELECT @ipC = LEFT(@ip, PATINDEX('%.%', @ip) - 1 )
   SELECT @ip = RIGHT(@ip, LEN(@ip) - LEN(@ipC) - 1 )

   SELECT @ipD = @ip
   RETURN ( @ipA * 256*256*256 ) + ( @ipB * 256*256 ) + ( @ipC * 256 ) + @ipD
END
   RETURN @ipI
END
CREATE OR REPLACE FUNCTION Dot2LongIP(text) RETURNS bigint AS '
SELECT
split_part($1,''.'',1)::int8*(256*256*256)+
split_part($1,''.'',2)::int8*(256*256)+
split_part($1,''.'',3)::int8*256+
split_part($1,''.'',4)::int8;
'
LANGUAGE 'SQL';
Convert IPv4 IP Address to IP Number in Decimal Integer (IPv4 IP Address is in cell A1):
=((VALUE(LEFT(A1, FIND(".", A1)-1)))*256^3)+((VALUE(MID(A1, FIND(".", A1)+1, FIND(".", A1, FIND(".", A1)+1)-FIND(".", A1)-1)))*256^2)+((VALUE(MID(A1, FIND(".", A1, FIND(".", A1)+1)+1, FIND(".", A1, FIND(".", A1, FIND(".", A1)+1)+1)-FIND(".", A1, FIND(".", A1)+1)-1)))*256)+(VALUE(RIGHT(A1, LEN(A1)-FIND(".", A1, FIND(".", A1, FIND(".", A1)+1)+1))))

Convert IP Number in Decimal Integer to IPv4 IP Address (Decimal Integer is in cell A2):
=IF(A2<>"", CONCATENATE(INT(A2/256^3), ".", INT(MOD(A2, (256^3))/(256^2)), ".", INT(MOD(MOD(A2, 256^3), 256^2)/256), ".", MOD(MOD(MOD(A2, 256^3), 256^2), 256)), "")
$ipv6 = '2404:6800:4001:805::1006';
$int = inet_pton($ipv6);
$bits = 15;

$ipv6long = 0;

while($bits >= 0){
	$bin = sprintf("%08b", (ord($int[$bits])));

	if($ipv6long){
		$ipv6long = $bin . $ipv6long;
	}
	else{
		$ipv6long = $bin;
	}
	$bits--;
}

$ipv6long = gmp_strval(gmp_init($ipv6long, 2), 10);
java.math.BigInteger Dot2LongIP(String ipv6) {
	java.net.InetAddress ia = java.net.InetAddress.getByName(ipv6);
	byte byteArr[] = ia.getAddress();

	if (ia instanceof java.net.Inet6Address) {
		java.math.BigInteger ipnumber = new java.math.BigInteger(1, byteArr);
		return ipnumber;
	}
}
<cfscript>
	ipv6 = "2404:6800:4001:805::1006"
	ipv6New = replace(ipv6,":","","All")
	ipv6long = createObject("java","java.math.BigInteger").init(ipv6New , 16).toString()
</cfscript>
string strIP = "2404:6800:4001:805::1006";
System.Net.IPAddress address;
System.Numerics.BigInteger ipnum;

if (System.Net.IPAddress.TryParse(strIP, out address)) {
	byte[] addrBytes = address.GetAddressBytes();

	if (System.BitConverter.IsLittleEndian) {
		System.Collections.Generic.List byteList = new System.Collections.Generic.List(addrBytes);
		byteList.Reverse();
		addrBytes = byteList.ToArray();
	}

	if (addrBytes.Length > 8) {
		//IPv6
		ipnum = System.BitConverter.ToUInt64(addrBytes, 8);
		ipnum <<= 64;
		ipnum += System.BitConverter.ToUInt64(addrBytes, 0);
	} else {
		//IPv4
		ipnum = System.BitConverter.ToUInt32(addrBytes, 0);
	}
}
Dim strIP As String = "2404:6800:4001:805::1006"
Dim address As System.Net.IPAddress
Dim ipnum As System.Numerics.BigInteger

If System.Net.IPAddress.TryParse(strIP, address) Then
	Dim addrBytes() As Byte = address.GetAddressBytes()

	If System.BitConverter.IsLittleEndian Then
		Dim byteList As New System.Collections.Generic.List(Of Byte)(addrBytes)
		byteList.Reverse()
		addrBytes = byteList.ToArray()
	End If

	If addrBytes.Length > 8 Then
		'IPv6
		ipnum = System.BitConverter.ToUInt64(addrBytes, 8)
		ipnum <<= 64
		ipnum += System.BitConverter.ToUInt64(addrBytes, 0)
	Else
		'IPv4
		ipnum = System.BitConverter.ToUInt32(addrBytes, 0)
	End If
End If
use NetAddr::IP;

sub dot2LongIP {
	my $ip_address = shift(@_);
	my $ip_number = NetAddr::IP->new($ip_address) or die;
	return $ip_number->bigint;
}
require 'ipaddr'

def dot2LongIP(ipv6) 
	ipnum = IPAddr.new(ipv6)
	return ipnum.to_i
end
import ipaddress
	
def dot2LongIP(ipv6):
	return int(ipaddress.IPv6Address(ipv6))
#include <arpa/inet.h>
#include <inttypes.h>

typedef unsigned __int128 uint128_t;

uint128_t Dot2LongIP(const char* ipv6) {
	struct sockaddr_in6 sa;
	inet_pton(AF_INET6, ipv6, &(sa.sin6_addr));
	uint128_t ipnum = 0;
	uint128_t octet = 0;
	int i;
	for (i = 0; i < (sizeof(sa.sin6_addr.s6_addr) / sizeof(sa.sin6_addr.s6_addr[0])); i++) {
		octet = ((uint128_t)sa.sin6_addr.s6_addr[i] << ((uint128_t)(15 - i) * 8));
		ipnum = ipnum + octet;
	}
	return ipnum;
}

Firstly, convert the IP address to IP number format. Search IP-Country Database using IP number to match a record that has the IP Number between the Beginning IP Number and the Ending IP Number.

For example, IP Address "72.77.138.60" is "1213041212" in IP Number. It matched the following recordset in the database.

"1213041208","1213041215","US","UNITED STATES"

The IP2Location will display the "-" in country field when the IP address range is still unallocated to any countries. It is also known as reserved IP address range.

First, import this database into your MSSQL, MS-ACCESS, PL/SQL, MYSQL or other RDMS. Use an SQL query to get the matching recordset.

Example of SQL Query (MSSQL)

SELECT [COUNTRY NAME COLUMN], [REGION NAME COLUMN], [CITY NAME COLUMN], [LATITUDE COLUMN], [LONGITUDE COLUMN], [ZIP CODE COLUMN], [TIME ZONE COLUMN], [ISP COLUMN], [DOMAIN NAME COLUMN], [NETSPEED COLUMN], [IDD CODE COLUMN], [AREA CODE COLUMN], [WEATHER STATION CODE COLUMN], [WEATHER STATION NAME COLUMN], [MCC COLUMN], [MNC COLUMN], [BRAND NAME COLUMN]
FROM [IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE TABLE]
WHERE [SEARCH IP NO] BETWEEN [IP FROM COLUMN] AND [IP TO COLUMN]
						

Example of SQL Query (MYSQL)

SELECT [COUNTRY NAME COLUMN], [REGION NAME COLUMN], [CITY NAME COLUMN], [LATITUDE COLUMN], [LONGITUDE COLUMN], [ZIP CODE COLUMN], [TIME ZONE COLUMN], [ISP COLUMN], [DOMAIN NAME COLUMN], [NETSPEED COLUMN], [IDD CODE COLUMN], [AREA CODE COLUMN], [WEATHER STATION CODE COLUMN], [WEATHER STATION NAME COLUMN], [MCC COLUMN], [MNC COLUMN], [BRAND NAME COLUMN]
FROM [IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE TABLE]
WHERE ([IP FROM COLUMN] <= [SEARCH IP NO]) AND ([IP TO COLUMN] >= [SEARCH IP NO])
						

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("X_FORWARDED_FOR") == null) {
        String ipaddress = request.getRemoteAddr();
    } else {
        String ipaddress = request.getHeader("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#) 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

Yes, we will deliver the notification via email when the update is available in the download area.

Ownership of IP addresses change hands from time to time. Therefore, a small percentage of IP address blocks needs to be updated every year. Our full version database is updated monthly to make sure it is always accurate.

You can visit ip2location.com and make the purchase. Alternatively, you can also upgrade from LITE edition under account area. We will generate an unique login/password to allow you to download the database for one year after we have processed your order.

You will receive your login and password through email immediately after payment is authorized. You can use your credentials to download the database from our website at anytime. The database is in a ZIP compressed format to save your bandwidth and downloading time.

You can redistribute one copy of the LITE database with your application with attribution. However, you need to inform all users to register for an individual license in http://lite.ip2location.com to download monthly updates. Third party database repository is not allowed.

LocaProxy.com. It provides multi-location HTTP proxies to help businesses test geolocation applications. This solution reduces the total cost of testing by supplying the Distributed Infrastructure as a Service.