LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

ip2region-IP到地名(国家区域省份城市县地址)映射查询库

admin
2023年7月3日 14:30 本文热度 501

ip2region—— 准确率 99.9% 的 ip 地址定位库,0.0x 毫秒级查询,数据库文件大小只有 1.5M,提供了 java、php、c、python、node.js、golang 查询绑定和 Binary、B 树、内存三种查询算法,妈妈再也不用担心我的 ip 地址定位!

1. 99.9% 准确率,定时更新:

数据聚合了一些知名 ip 到地名查询提供商的数据,这些是他们官方的的准确率,经测试着实比纯真啥的准确多了。

每次聚合一下数据需要 1-2 天,会不定时更新。 

2. 标准化的数据格式:

每条 ip 数据段都固定了格式:城市 Id | 国家 | 区域 | 省份 | 城市 | ISP

只有中国的数据精确到了城市,其他国家只能定位到国家,后前的选项全部是 0,已经包含了全部你能查到的大大小小的国家。

(请忽略前面的城市 Id,个人项目需求) 

3. 体积小:

生成的数据库文件 ip2region.db 只有 1.5M (1.2 版本前 3.5M) 

4. 多查询客户端的支持,0.0x 毫秒级别的查询

已经集成的客户端有:java, php, c,python,php 扩展,nodejs,golang。

提供了两种查询算法,响应时间如下:
客户端/binary算法/b-tree算法/Memory算法:
java/0.x毫秒/0.x毫秒/0.1x毫秒 (使用RandomAccessFile)
php/0.x毫秒/0.1x毫秒/0.1x毫秒 (php扩展将有更快的速度)c/0.0x毫秒/0.0x毫秒/0.00x毫秒(b-tree算法基本稳定在0.02x毫秒级别)
python/0.x毫秒/0.1x毫秒/0.1x毫秒

任何客户端 b-tree 都比 binary 算法快

5. 测试程序:

    java:

	cd binding/java
	ant all
	java -jar ip2region-{version}.jar ./data/ip2region.db

php:

    php binding/php/testSearch ./data/ip2region.db

c:

cd binding/c/
    gcc -g -O2 testSearch.c ip2region.c
    ./a.out ../../data/ip2region.db

均会看到如下界面:

initializing  B-tree ... 
+----------------------------------+
| ip2region test script            |
| Author: chenxin619315@gmail.com  |
| Type 'quit' to exit program      |
+----------------------------------+
ip2region>>

输入 ip 地址开始测试,第一次会稍微有点慢,在运行命令后面接入 binary,memory 来尝试对应算法,建议使用 b-tree 算法,有速度和并发追求的使用 memory 算法。具体集成请参考不同客户端的测试源码。 


C#使用方法:

IP2Region.Net

IP2Region c# xdb client

Installation

Install the package with NuGet

Install-Package IP2Region.Net

Usage

using IP2Region.Net.XDB;

 

//use default db and cache whole xdb file

Searcher searcher = new Searcher();

searcher.Search("ipaddress value");

 

/*

 * custom cache policy and xdb file path

 * CachePolicy.Content default cache policy , cache whole xdb file , thread safe

 * CachePolicy.VectorIndex cache vector index , reduce the number of IO operations , not thread safe!

 * CachePolicy.File no cache , not thread safe!

 */

Searcher searcher = new Searcher(CachePolicy.File, "your xdb file path");

ASP.NET Core Usage

services.AddSingleton<ISearcher,Searcher>();

Performance

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.856/21H2)
AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx, 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.400
  [Host]     : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2
MethodMeanErrorStdDev
CachePolicy_Content224.6 ns4.44 ns7.41 ns
CachePolicy_VectorIndex11,648.4 ns231.98 ns457.91 ns

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.


该文章在 2023/7/3 14:38:04 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved