该数据库提供了一个解决方案,只需几个简单的步骤即可确定任何IP地址的来源国。要查找IP地址,您将需要从网络协议或Web服务器的服务器端变量中检索IP地址。接下来,解析IP地址并将IP地址转换为十进制格式的IP号,以加快数据库查询的速度。然后,从IP2Location™地理位置数据库反向查找IP号以获得地理位置。
对于个人或商业用途,它是免费的,但需注明出处并注明出处,如下所述,
如果您希望获得更高的数据准确性,更多记录和客户支持,请获取商业版。请访问产品比较页面以获取更多信息。
Let's explore this database which provides a valuable resource of geolocation data for free now!
Sign Up For Free将IP地址翻译到国家/地区。
当前版本 | November 2024 |
---|---|
下次更新 | December 2024 |
IPv4 数据库大小 |
BIN: 2.43 MB CSV: 11.7 MB (251,868 行) |
IPv6 数据库大小 |
BIN: 9.66 MB CSV: 48.9 MB (604,762 行) |
数据库格式 |
二进制 (BIN)
ASCII文本文件 (CSV) |
名称 | 类型 | 描述 |
---|---|---|
ip_from | INT (10)† / DECIMAL (39,0)†† | 第一个IP地址显示netblock。 |
ip_to | INT (10)† / DECIMAL (39,0)†† | 上一个IP地址显示netblock。 |
country_code | CHAR(2) | 基于ISO 3166的两个字符的国家/地区代码。 |
country_name | VARCHAR(64) | 基于ISO 3166的国家/地区名称。 |
† IPv4
†† IPv6
††† Latitude and Longitude are often near the center of population. These values are not precise and should not be used to identify a particular address or household.
以下是为IPv4和IPv6数据设置数据库的步骤。
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),
PRIMARY KEY (`ip_to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
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;
CREATE DATABASE ip2location
GO
USE ip2location
GO
CREATE TABLE [ip2location].[dbo].[ip2location_db1](
[ip_from] bigint NOT NULL,
[ip_to] bigint NOT NULL,
[country_code] nvarchar(2) NOT NULL,
[country_name] nvarchar(64) NOT NULL
) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX [ip_to] ON [ip2location].[dbo].[ip2location_db1]([ip_to]) ON [PRIMARY]
GO
BULK INSERT [ip2location].[dbo].[ip2location_db1]
FROM '{PATH TO IP2LOCATION-LITE-DB1.CSV}'
WITH
(
FORMATFILE = '{PATH TO DB1.FMT}'
)
GO
注意:您将需要复制以下FMT代码并将其保存为计算机上名为DB1.FMT的文件。
12.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 "\",\"" 4 country_name Latin1_General_CI_AI
CREATE DATABASE ip2location WITH ENCODING 'UTF8';
\c ip2location
CREATE TABLE ip2location_db1(
ip_from bigint NOT NULL,
ip_to bigint 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)
);
COPY ip2location_db1 FROM 'IP2LOCATION-LITE-DB1.CSV' WITH CSV QUOTE AS '"';
mongoimport -u USERNAME -p PASSWORD --authenticationDatabase admin --drop --db ip2location --collection ip2location_db1 --type csv --file "IP2LOCATION-LITE-DB1.CSV" --fields ip_from,ip_to,country_code,country_name
CREATE DATABASE ip2location;
USE ip2location;
CREATE TABLE `ip2location_db1_ipv6`(
`ip_from` DECIMAL(39,0) UNSIGNED,
`ip_to` DECIMAL(39,0) UNSIGNED,
`country_code` CHAR(2),
`country_name` VARCHAR(64),
PRIMARY KEY (`ip_to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
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;
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 CLUSTERED INDEX [ip_to] ON [ip2location].[dbo].[ip2location_db1_ipv6]([ip_to]) ON [PRIMARY]
GO
BULK INSERT [ip2location].[dbo].[ip2location_db1_ipv6]
FROM '{PATH TO IP2LOCATION-LITE-DB1.IPV6.CSV}'
WITH
(
FORMATFILE = '{PATH TO DB1.FMT}'
)
GO
注意:您将需要复制以下FMT代码并将其保存为计算机上名为DB1.FMT的文件。 FMT代码的第一行指示bcp的版本。请根据安装的MS-SQL更改版本。
12.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 "\",\"" 4 country_name Latin1_General_CI_AI
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)
);
COPY ip2location_db1_ipv6 FROM 'IP2LOCATION-LITE-DB1.IPV6.CSV' WITH CSV QUOTE AS '"';
mongoimport -u USERNAME -p PASSWORD --authenticationDatabase admin --drop --db ip2location --collection ip2location_db1_ipv6 --type csv --file "IP2LOCATION-LITE-DB1.IPV6.CSV" --fields ip_from,ip_to,country_code,country_name
IP2Location提供了一个免费的,预先配置且可立即运行的AMI和映像,可轻松设置数据库。
请查看通用条款和条件中的数据库许可。
Enhance your applications with essential geolocation data by using our FREE databases.