版权声明:本文为博主徐松亮的原创作品,未经允许不得转载,多谢支持! *** :5387603
推荐点击此链接:欢迎进入徐松亮博客一站式导航搜索(随时更新)
目录
一,概念
场景
场景解决
具体方案
数据到哪去查呢?
本文用什么变成语言?
本文用GeoLiteCity的在线查询还是离线查询?
离线数据源的定期更新
二,准备工作
python环境
安装MaxMind公司的开源数据库GeoLiteCity:
三,代码讲解
四,源码
五,运行效果
六,调试记录
pip install geoip2
等待安装完成
下载数据包
下载网址:https://dev.maxmind.com/zh-hans/geoip/geoip2/geolite2/
#!D:/Program Files/Python37/python import geoip2.database # This creates a Reader object. You should use the same object # across multiple requests as creation of it is expensive. reader = geoip2.database.Reader( '../../../xsl_use_lib/geolite2/GeoLite2-City/GeoLite2-City.mmdb') def ip_print_AddrInfo(ip): # Replace "city" with pthe method corresponding to the database # that you are using, e.g., "country". #----------------------------------------------- # 载入指定IP相关数据 response = reader.city(ip) #读取国家代码 Country_IsoCode = response.country.iso_code #读取国家名称 Country_Name = response.country.name #读取国家名称(中文显示) Country_NameCN = response.country.names['zh-CN'] #读取州(国外)/省(国内)名称 Country_SpecificName = response.subdivisions.most_specific.name #读取州(国外)/省(国内)代码 Country_SpecificIsoCode = response.subdivisions.most_specific.iso_code #读取城市名称 City_Name = response.city.name #读取邮政编码 City_PostalCode = response.postal.code #获取纬度 Location_Latitude = response.location.latitude #获取经度 Location_Longitude = response.location.longitude #------------------------------------------------打印 print('[*] Target: ' + ip + ' GeoLite2-Located ') print(' [+] Country_IsoCode : ' + Country_IsoCode) print(' [+] Country_Name : ' + Country_Name) print(' [+] Country_NameCN : ' + Country_NameCN) print(' [+] Country_SpecificName : ' + Country_SpecificName) print(' [+] Country_SpecificIsoCode: ' + Country_SpecificIsoCode) print(' [+] City_Name : ' + City_Name) if City_PostalCode != None: print(' [+] City_PostalCode : ' + City_PostalCode) print(' [+] Location_Latitude : ' + str(Location_Latitude)) print(' [+] Location_Longitude : ' + str(Location_Longitude)) ip = '119.108.116.209' ip_print_AddrInfo(ip)
黑客对电子商务体系的损害(2)环境检测 }图3. Huawei用户看到的经过USERPIN认证的CP消息工作脚本 prefs = {'dow...
浓缩课程 每年6学期 迅速提升等级 为数不多提供学生宿舍的语学院 目录 一、基本介绍 教育方针和理念 教授及教职员 二、教学环境 三、宿舍 四、2017年大学韩国语课程日程 五、...
院校排名是很多考研考生关注的重点,对于考研专业相关院校排名情况更是考生选择报考高校的关注焦点,如何获取这些考研专业院校排名信息?今天中公考研小编整理“2020年考研环境科学专业考研院校排名”内容...
湿疹虽然不是什么大病,但是如果一旦患了湿疹,会给人带来极大的困扰。那么哪些因素会引起湿疹呢?如果患上了湿疹的症状,又应该怎么去治疗呢?为了预防患上湿疹,我们应该在日常生活当中注意哪些?要想知道以上三个...
本报北京9月27日电(记者冯华、余建斌)记者从国家航天局获悉:27日11时23分,我国在太原卫星发射中心用长征四号乙运载火箭,以一箭双星的方式成功发射环境减灾二号A、B卫星。该组卫星将接替在轨超期运行...
当一个产物呈现问题时,大量用户涌入客服页面,会呈现列队时间过长,客服效率低,从而导致用户对产物的满足度下降。那么如何办理这个问题呢?本文作者基于本身事情履历,从四个方面临这个问题展开阐明,但愿对你有辅...