DB1.LITE IP2Location LITE IP-COUNTRY Database
DB1.LITE

IP2Location™ LITE IP-COUNTRY Database provides a solution to determine the country of origin for any IP address in a few simple steps. First, retrieve the IP address from the networking protocol or server-side variable of the Web server. Next, translate the IP address to an IP number in decimal format to speed up the database query. Lastly, reverse lookup the IP number from the IP2Location™ database to pinpoint the exact geographical location.

The DB1.LITE edition is licensed under Creative Commons Attribution-ShareAlike 4.0 International License. It is free for personal or commercial use with attribution required by mentioning the use of this data as follows,

This site or product includes IP2Location LITE data available from <a href="http://www.ip2location.com">http://www.ip2location.com</a>.

Please get the commercial edition if you are looking for high data accuracy, more records & customer support. Please visit product comparison page for more information. Or, register for other free LITE package that provide you more granularity information of IP address.

Product Features

Features Translates IP address to country.
Current Version October 2014
Database Size 958.51 kB (60,932 Rows)
Database Format ASCII Text File (Comma Delimited) & Binary (BIN)

Database Fields

Name Type Description
ip_from INT (10) /
DECIMAL (39,0)††
First IP address in netblock.
ip_to INT (10) /
DECIMAL (39,0)††
Last IP address in netblock.
country_code CHAR(2) Two-character country code based on ISO 3166.
country_name VARCHAR(64) Country name based on ISO 3166.
IPv4
†† IPv6

Database Setup

Below are the steps to set up the database for both IPv4 and IPv6 data

Create SQL table

MS-SQL

CREATE DATABASE ip2location
GO

USE ip2location
GO

CREATE TABLE [ip2location].[dbo].[ip2location_db1](
	[ip_from] float NOT NULL,
	[ip_to] float NOT NULL,
	[country_code] nvarchar(2) NOT NULL,
	[country_name] nvarchar(64) NOT NULL,
) ON [PRIMARY]
GO

CREATE INDEX [ip_from] ON [ip2location].[dbo].[ip2location_db1]([ip_from]) ON [PRIMARY]
GO

CREATE INDEX [ip_to] ON [ip2location].[dbo].[ip2location_db1]([ip_to]) ON [PRIMARY]
GO
										

MySQL

CREATE DATABASE ip2location;
USE ip2location;
CREATE TABLE `ip2location_db1`(
	`ip_from` INT(10) UNSIGNED,
	`ip_to` INT(10) UNSIGNED,
	`country_code` CHAR(2),
	`country_name` VARCHAR(64),
	INDEX `idx_ip_from` (`ip_from`),
	INDEX `idx_ip_to` (`ip_to`),
	INDEX `idx_ip_from_to` (`ip_from`, `ip_to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
										

PostgreSQL

CREATE DATABASE ip2location WITH ENCODING 'UTF8';
\c ip2location
CREATE TABLE ip2location_db1(
	ip_from integer(10) NOT NULL,
	ip_to integer(10) NOT NULL,
	country_code character(2) NOT NULL,
	country_name character varying(64) NOT NULL,
	CONSTRAINT ip2location_db1_pkey PRIMARY KEY (ip_from, ip_to)
);
										
Import the database into MS-SQL/MySQL/PostgreSQL database

MS-SQL

BULK INSERT [ip2location].[dbo].[ip2location_db1]
    FROM 'C:\[path to your CSV file]\IP2LOCATION-LITE-DB1.CSV'
    WITH
    (
        FORMATFILE = 'C:\[path to your DB1.FMT file]\DB1.FMT'
    )
GO
										

DB1.FMT

NOTE: You will need to copy the FMT code below and save it as a file named DB1.FMT on your computer.
The first line of the FMT code indicates the version of bcp. Please change the version as according to your MS-SQL installed.

SQL Server 200810.0
SQL Server 20059.0
SQL Server 20008.0
SQL Server 7.07.0
SQL Server 6.56.5

10.0
5
1 SQLCHAR 0 1 "\"" 0 first_double_quote  Latin1_General_CI_AI
2 SQLCHAR 0 20 "\",\"" 1 ip_from ""
3 SQLCHAR 0 20 "\",\"" 2 ip_to ""
4 SQLCHAR 0 2 "\",\"" 3 country_code Latin1_General_CI_AI
5 SQLCHAR 0 64 "\"\r\n" 4 country_name Latin1_General_CI_AI
										

MySQL

LOAD DATA LOCAL
	INFILE 'IP2LOCATION-LITE-DB1.CSV'
INTO TABLE
	`ip2location_db1`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;
										

PostgreSQL

COPY ip2location_db1 FROM 'IP2LOCATION-LITE-DB1.CSV' WITH CSV QUOTE AS '"';
										
Create SQL table for IPv6 data

MS-SQL

CREATE DATABASE ip2location
GO

USE ip2location
GO

CREATE TABLE [ip2location].[dbo].[ip2location_db1_ipv6](
	[ip_from] char(39) NOT NULL,
	[ip_to] char(39) NOT NULL,
	[country_code] nvarchar(2) NOT NULL,
	[country_name] nvarchar(64) NOT NULL,
) ON [PRIMARY]
GO

CREATE INDEX [ip_from] ON [ip2location].[dbo].[ip2location_db1_ipv6]([ip_from]) ON [PRIMARY]
GO

CREATE INDEX [ip_to] ON [ip2location].[dbo].[ip2location_db1_ipv6]([ip_to]) ON [PRIMARY]
GO
										

MySQL

CREATE DATABASE ip2location;
USE ip2location;
CREATE TABLE `ip2location_db1_ipv6`(
	`ip_from` DECIMAL(39,0) UNSIGNED NULL DEFAULT NULL,
	`ip_to` DECIMAL(39,0) UNSIGNED NOT NULL,
	`country_code` CHAR(2),
	`country_name` VARCHAR(64),
	INDEX `idx_ip_from` (`ip_from`),
	INDEX `idx_ip_to` (`ip_to`),
	INDEX `idx_ip_from_to` (`ip_from`, `ip_to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
										

PostgreSQL

CREATE DATABASE ip2location WITH ENCODING 'UTF8';
\c ip2location
CREATE TABLE ip2location_db1_ipv6(
	ip_from decimal(39,0) NOT NULL,
	ip_to decimal(39,0) NOT NULL,
	country_code character(2) NOT NULL,
	country_name character varying(64) NOT NULL,
	CONSTRAINT ip2location_db1_pkey PRIMARY KEY (ip_from, ip_to)
);
										
Import the database into MS-SQL/MySQL/PostgreSQL database

MS-SQL

BULK INSERT [ip2location].[dbo].[ip2location_db1_ipv6]
    FROM 'C:\[path to your CSV file]\IP2LOCATION-LITE-DB1.IPV6.CSV'
    WITH
    (
        FORMATFILE = 'C:\[path to your DB1.FMT file]\DB1.FMT'
    )
GO
										

DB1.FMT

NOTE: You will need to copy the FMT code below and save it as a file named DB1.FMT on your computer.
The first line of the FMT code indicates the version of bcp. Please change the version as according to your MS-SQL installed.

SQL Server 200810.0
SQL Server 20059.0
SQL Server 20008.0
SQL Server 7.07.0
SQL Server 6.56.5

10.0
5
1 SQLCHAR 0 1 "\"" 0 first_double_quote  Latin1_General_CI_AI
2 SQLCHAR 0 39 "\",\"" 1 ip_from ""
3 SQLCHAR 0 39 "\",\"" 2 ip_to ""
4 SQLCHAR 0 2 "\",\"" 3 country_code Latin1_General_CI_AI
5 SQLCHAR 0 64 "\"\r\n" 4 country_name Latin1_General_CI_AI
										

NOTE: Due to the fact that SQL Server does not support a number with more than 38 digits, we have to store the IP From and IP To fields as zero padded strings to enable sorting. Please visit this tutorial on how to add the padding, enable cluster index and make the query.

MySQL

LOAD DATA LOCAL
	INFILE 'IP2LOCATION-LITE-DB1.IPV6.CSV'
INTO TABLE
	`ip2location_db1_ipv6`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;
										

PostgreSQL

COPY ip2location_db1_ipv6 FROM 'IP2LOCATION-LITE-DB1.IPV6.CSV' WITH CSV QUOTE AS '"';
										

Amazon AMI

For Amazon AWS users, you can simply click on IP2Location Geolocation MySQL Server and set up the database in just a few steps. IP2Location Geolocation MySQL Server is a free, pre-configured & ready-to-run MySQL server AMI with IP2Location Geolocation database setup scripts.

Docker Image

IP2Location provides a free, pre-configured & ready-to-run Docker image to easily set up the database.

IP2Location BIN Database

Please visit IP2Location Developers and IP2Location Tutorials for details. Sample BIN databases and source codes are available for download.

Commercial Edition Upgrade

Ready to upgrade to our commercial edition for better accuracy?

  1. Login to account area.
  2. Click on the Upgrade button (on the right of the package listing).
  3. Select the [DB1] IP-Country Database and complete the payment checkout process.
  4. Download DB1-IP-COUNTRY.CSV.ZIP (or DB1-IPV6-COUNTRY.CSV.ZIP) from the account area.
  5. Unzip the file and import the IPCountry.csv into the database.

You can automate the download process using the free download script in command prompt or shell. Please visit IP2Location DB1 for details.

License Agreement: General Terms and Conditions for the database licensing.