* Begining of IP address range
* Ending of IP address range
* Two-character country code based on ISO 3166
* Three-character country code based on ISO 3166
* Country name based on ISO 3166
您可以通过创建包含以下字段的表来将此数据导入到任何数据库中:
FIELD DATA TYPE FIELD DESCRIPTION
IP_FROM NUMERICAL (DOUBLE) Beginning of IP address range.
IP_TO NUMERICAL (DOUBLE) Ending of IP address range.
COUNTRY_CODE2 CHAR(2) Two-character country code based on ISO 3166.
COUNTRY_CODE3 CHAR(3) Three-character country code based on ISO 3166.
COUNTRY_NAME VARCHAR(50) Country name based on ISO 3166
将数据导入其中后,您可以查询上面的表以查找国家/地区通过发出以下 Select 来获取相应的 IP 号码语句:
SELECT COUNTRY_NAME FROM <TableName> WHERE IP_FROM <= IP Number and IP_TO >= IP Number
其中给定 ABCD IP 的 IP 编号由以下公式计算:
IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
Have a look to the IP-to-Country Handbook The ip-to-country.csv file contains five fields:
* Begining of IP address range
* Ending of IP address range
* Two-character country code based on ISO 3166
* Three-character country code based on ISO 3166
* Country name based on ISO 3166
You can import this data into any database by creating a table with the following fields:
FIELD DATA TYPE FIELD DESCRIPTION
IP_FROM NUMERICAL (DOUBLE) Beginning of IP address range.
IP_TO NUMERICAL (DOUBLE) Ending of IP address range.
COUNTRY_CODE2 CHAR(2) Two-character country code based on ISO 3166.
COUNTRY_CODE3 CHAR(3) Three-character country code based on ISO 3166.
COUNTRY_NAME VARCHAR(50) Country name based on ISO 3166
You can query the above table, after you have imported the data into it, to find the country of a corresponding IP Number by issuing the following Select statement:
SELECT COUNTRY_NAME FROM <TableName> WHERE IP_FROM <= IP Number and IP_TO >= IP Number
where IP Number of a given A.B.C.D IP, is calculated by :
IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
发布评论
评论(4)
我编写了一个名为 ip2c 的小库来做到这一点。它使用 webhosting.info 中的数据库,但也支持 Software77。
它将 CSV 信息转换为紧凑的二进制格式,并且可以直接在文件、内存或内存映射文件中进行搜索。
Java API 的用法与此类似:
I wrote a small lib called ip2c to do just that. it uses the database from webhosting.info but also supports that from Software77.
It converts the CSV info a compact binary format and can do the search straight on the file, in memory or in a memory mapped file.
The Java API usage is similar to this:
查看IP 到国家/地区手册
ip-to-country.csv 文件包含五个字段:
您可以通过创建包含以下字段的表来将此数据导入到任何数据库中:
将数据导入其中后,您可以查询上面的表以查找国家/地区通过发出以下 Select 来获取相应的 IP 号码语句:
其中给定 ABCD IP 的 IP 编号由以下公式计算:
Have a look to the IP-to-Country Handbook
The ip-to-country.csv file contains five fields:
You can import this data into any database by creating a table with the following fields:
You can query the above table, after you have imported the data into it, to find the country of a corresponding IP Number by issuing the following Select statement:
where IP Number of a given A.B.C.D IP, is calculated by :
对于 IPv4,您可以按以下格式存储:
当您需要查找 IP 地址时,执行以下查询
这将为您提供 IP 地址的国家/地区
For IPv4 you can store in the following format:
When you need to look up the IP address execute the following query
This will give you the country for the IP address
您可以仅为范围的 ipTo(高边界)值构建索引并使用查询:(
假设范围不会像 MaxMind 数据库中那样重叠)
You can build index only for ipTo (high boundary) values of ranges and use query:
(it's assumed that ranges do not overlap as in MaxMind database)