当前位置: 首页 > news >正文

准确率99.9%的离线IP地址定位库 ip2region - python 示例

简介:ip2region是一个离线IP地址定位库和IP定位数据管理框架,10微秒级别的查询效率,提供了众多主流编程语言的 xdb 数据生成和查询客户端实现。号称准确率99.9%的开源离线IP地址定位库。

历史攻略:

Python:暴力破解密码 - 压缩包、web实战

Python:暴力破解密码

真伪之眼:探索信息纷争的艺术

Python:浏览网页暴露多少信息?

GitHub地址:

https://github.com/lionsoul2014/ip2region

使用步骤:

1、下载源码和数据

https://github.com/lionsoul2014/ip2region/archive/refs/heads/master.zip

2、本质就是导入和使用data目录下的 ip2region.xdb

官方示例代码:iptest.py

# Copyright 2022 The Ip2Region Authors. All rights reserved.
# Use of this source code is governed by a Apache2.0-style
# license that can be found in the LICENSE file.
#from xdbSearcher import XdbSearcherdef searchWithFile():# 1. 创建查询对象dbPath = "ip2region.xdb"searcher = XdbSearcher(dbfile=dbPath)# 2. 执行查询ip = "1.2.3.4"region_str = searcher.searchByIPStr(ip)print(region_str)# 3. 关闭searchersearcher.close()def searchWithVectorIndex():# 1. 预先加载整个 xdbdbPath = "ip2region.xdb"vi = XdbSearcher.loadVectorIndexFromFile(dbfile=dbPath)# 2. 使用上面的缓存创建查询对象, 同时也要加载 xdb 文件searcher = XdbSearcher(dbfile=dbPath, vectorIndex=vi)# 3. 执行查询ip = "1.2.3.4"region_str = searcher.search(ip)print(region_str)# 4. 关闭searchersearcher.close()def searchWithContent():# 1. 预先加载整个 xdbdbPath = "ip2region.xdb"cb = XdbSearcher.loadContentFromFile(dbfile=dbPath)# 2. 仅需要使用上面的全文件缓存创建查询对象, 不需要传源 xdb 文件searcher = XdbSearcher(contentBuff=cb)# 3. 执行查询# ip = "111.112.113.114"ip = "101.102.103.104"region_str = searcher.search(ip)print(region_str)# 4. 关闭searchersearcher.close()if __name__ == '__main__':searchWithContent()

运行结果:

中国|0|宁夏|固原市|电信
中国|0|台湾省|台北|0
http://www.lryc.cn/news/500206.html

相关文章:

  • wordpress网站使用Linux宝塔面板和SQL命令行导入导出超过50M限制的数据库
  • 开发基础(3):开发应用沉浸式效果 组件安全区方案
  • Python中的数据可视化实战
  • 计算机毕设-基于springboot的甜品店管理系统的设计与实现(附源码+lw+ppt+开题报告)
  • SpringMVC纯注解快速开发
  • 【JAVA】Java高级:多数据源管理与Sharding:在Spring Boot应用中实现多数据源的管理
  • 汽车网络安全 -- IDPS如何帮助OEM保证车辆全生命周期的信息安全
  • 黑马点评项目测试总结
  • 【Selenium】基于 WebDriverWait 爬取带有懒加载的静态页面
  • 【docker】docker compose 和 docker swarm
  • Javaweb 前端 ajax
  • 【蓝桥杯每日一题】重新排序
  • 《深入浅出HTTPS》读书笔记(16):消息验证码算法分类
  • 如何使用Apache HttpClient来执行GET、POST、PUT和DELETE请求
  • 数据结构-希尔排序
  • Spire.doc 合并word,复制word
  • 【Spring项目】表白墙,留言板项目的实现
  • 分布式事务-nacos/seata在windows环境下部署及开发
  • 分布式微服务架构下的密码安全性方案
  • 基于pytorch的深度学习基础4——损失函数和优化器
  • 网络安全信息收集(总结)更新
  • web斗地主游戏实现指北
  • SpringMVC其他扩展
  • 【Linux】网络服务
  • 工作:SolidWorks从3D文件导出2D的DWG或DXF类型文件方法
  • IDL学习笔记(五)MODIS数据(Grid)
  • JavaScript语言介绍
  • Lua使用点号和冒号的区别
  • LLM - 开源视觉多模态 LLaVA-CoT(o1) 深度推理模型 测试与源码 教程
  • Ansible的yum和saltstack的哪个功能相似