ip2region -- 查询IP地址

  1. ip2region
  2. 生成xdb数据库
  3. 使用方法

ip2region

是一个离线IP地址定位库和IP定位数据管理框架,10微秒级别的查询效率,提供了众多主流编程语言的xdb数据生成和查询客户端实现。
默认的返回的数据格式:国家|区域|省份|城市|ISP,缺省的地域信息默认是0

github文档地址:
https://github.com/lionsoul2014/ip2region/tree/master/binding/python

gitee文档地址:
https://gitee.com/lionsoul/ip2region/tree/master/maker/python

生成xdb数据库

生成方式:https://gitee.com/lionsoul/ip2region/tree/master/maker/python
(生成的时间可能比较久,需要耐心等待,9min)

仓库地址克隆:git clone https://gitee.com/lionsoul/ip2region.git

使用方法

from xdbSearcher import XdbSearcher

def searchWithFile():
    # 1. 创建查询对象
    dbPath = "../../data/ip2region.xdb"
    searcher = XdbSearcher(dbfile=dbPath)
    
    # 2. 执行查询
    ip = "1.2.3.4"
    region_str = searcher.searchByIPStr(ip)
    print(region_str)
    
    # 3. 关闭searcher
    searcher.close()

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。

文章标题:ip2region -- 查询IP地址

本文作者:伟生

发布时间:2025-05-05, 16:35:20

最后更新:2025-05-05, 17:16:37

原始链接:http://yoursite.com/2025/05/05/basic_22_search_ip/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏