版权声明:本文为博主徐松亮的原创作品,未经允许不得转载,多谢支持! *** :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)
平常用的虚拟主机的朋友可能很少会关注到Web服务器的搭建,但是对于那些购买了Windows、Linux VPS或服务器的朋友来说,如何在VPS服务器上快速搭建一个Web服务器就是最重要的问题了。...
湿疹虽然不是什么大病,但是如果一旦患了湿疹,会给人带来极大的困扰。那么哪些因素会引起湿疹呢?如果患上了湿疹的症状,又应该怎么去治疗呢?为了预防患上湿疹,我们应该在日常生活当中注意哪些?要想知道以上三个...
一直以为怀孕是最累的,没想到生完孩子后会有更多的事情等着你呢?比如宝宝特别喜欢抱睡怎么办?感觉胳膊都要断了,为什么宝宝一放下就容易醒呢?宝宝一放就醒的解决办法。 孩子喜欢抱睡怎么办 几乎所有的婴儿...
不念书小学早恋引导若凭据以上概念看,祝你乐成哦,孩子一般情防备况下是不会早恋的,早恋一小我私家的芳华期没有青涩的感引导情萌动,自觉危害发生免疫力。高中这种爱的感受是责任是动力。爱情因素要领未免太惋惜了...
2017年高考已经结束,新的高三学子们要开始备战新的高考了,对于高考生来说,选对一个专业比选大学还重要,很多想要报考吉林农业科技学院的学生想要了解该校的王牌专业有哪些?整理了报考吉林农业科技学院选择什...
香港中文大学简介 香港中文大学(The Chinese University of Hong Kong),简称港中大(CUHK),书 院联邦制大学建制,为东亚AACSB认证成员、亚太高校书院联盟成员...