初步构想:
通过IP地址来获取定位信息,并通过Python可视化界面显示出来。
准备工作:
如果没有tkinter,请安装pip install tkinter
安装geoip2模块(pip install geoip2)
下载离线IP解析数据库GeoLite2 City,放在你的项目根目录。
https://dev.maxmind.com/geoip/geoip2/geolite2/(注意MaxMind DB格式)
代码实现:
#! python3
# @Project: pythondemo - LocateFromIP.py
# @Info : 根据IP定位(离线版),并用tkinter创建GUI界面
# 文档:https://geoip2.readthedocs.io/en/latest/#database-example
import tkinter.messagebox,geoip2.database,re
class FindLocation(object):
def __init__(self):
# 加载数据库(官网上免费数据库),数据库文件在根目录
self.reader = geoip2.database.Reader('.\GeoLite2-City.mmdb')
# 创建主窗口,即为根窗口
self.root = tkinter.Tk(className='全球定位IP位置(离线版)')
# 创建一个输入框并设置尺寸
self.input_ip = tkinter.Entry(self.root,w

该博客介绍了如何使用Python3的geoip2库结合离线数据库GeoLite2 City进行IP定位,并通过GUI图形化界面展示定位结果。首先,确保安装了tkinter和geoip2模块,接着下载并配置IP数据库。最终,通过代码实现了从IP到地理位置信息的转换并以图形界面展示。
最低0.47元/天 解锁文章
7020

被折叠的 条评论
为什么被折叠?



