github lionsoul2014/ip2region v3.8.0

one day ago

重构 python binding 提供 IPv6 支持:

  1. py_ip2region pypi 包支持:
pip3 install py-ip2region
  1. utilsearcher 模块:
# 工具包模块,例如:ip 解析,版本信息,vectorIndex / buffer加载等
import ip2region.util as util
# xdb 查询实现模块
import ip2region.searcher as xdb

# 使用方式参考 python binding 的 ReadMe
  1. python binding 提供了对 IPv6 的查询支持,具体使用文档请参考 Python Binding,测试方式如下:
(.venv) ➜  python git:(master) python3 search_test.py --db=../../data/ip2region_v6.xdb 
ip2region xdb searcher test program
source xdb: ../../data/ip2region_v6.xdb (IPv6, vectorIndex)
type 'quit' to exit
ip2region>> ::
{region: , ioCount: 1, took: 180 μs}
ip2region>>  240e:3b7:3272:d8d0:3b7b:3ee0:1d39:848
{region: 中国|广东省|深圳市|家庭宽带, ioCount: 8, took: 251 μs}
ip2region>> 2001:3:ffff:ffff:ffff:ffff:ffff:ffff
{region: 0|0|内网IP|内网IP, ioCount: 18, took: 474 μs}
ip2region>>
  1. 查询平均耗时:Razer 笔记本 / Ubuntu (电源均衡模式) + SATA SSD / VectorIndex 缓存,bench 结果如下:
(.venv) ➜  python git:(master) ✗ python3 bench_test.py --db=../../data/ip2region_v6.xdb --src=../../data/ipv6_source.txt --cache-policy=vectorIndex
searcher -> {"version": IPv6, "db_path": "../../data/ip2region_v6.xdb", "v_index": 524288, "c_buffer": None}
Bench finished, {cachePolicy: vectorIndex, total: 1614544, took: 65.378 s, cost: 40 μs/op}

161.45 万个 IPv6 平均查询耗时为 40 微秒/次。

Don't miss a new ip2region release

NewReleases is sending notifications on new releases.