Python 安装 MaxMind GeoLite City
来源:互联网 发布:mac浏览器自动跳转 编辑:程序博客网 时间:2024/04/26 13:57
1、先安装 geoip c library
geoip c library >= 1.4.6 installed on your machine. >= 1.4.6 installed on your machine.
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.7.tar.gztar -xvzf GeoIP-1.4.7.tar.gzcd GeoIP-1.4.7./confiuremake make install
2、下载
GeoLite City Phthon版本
https://codeload.github.com/maxmind/geoip-api-python/zip/master
unzip master
$ python setup.py build$ python setup.py install3、下载GeoLiteCity.datwget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzgunzip GeoLiteCity.dat.gz4、用法>>> import GeoIP>>> geodb='/home/maxMind/GeoLiteCity.dat'>>> gi = GeoIP.open(geodb, GeoIP.GEOIP_STANDARD)>>> ip='180.76.1.3'>>> gi.record_by_addr(ip){'city': 'Beijing', 'region_name': 'Beijing', 'region': '22', 'area_code': 0, 'time_zone': 'Asia/Harbin', 'longitude': 116.38829803466797, 'metro_code': 0, 'country_code3': 'CHN', 'latitude': 39.92890167236328, 'postal_code': None, 'dma_code': 0, 'country_code': 'CN', 'country_name': 'China'}>>> gir = gi.record_by_name("www.google.com")>>> gir{'city': 'Mountain View', 'region_name': 'California', 'region': 'CA', 'area_code': 650, 'time_zone': 'America/Los_Angeles', 'longitude': -122.05740356445312, 'metro_code': 807, 'country_code3': 'USA', 'latitude': 37.4192008972168, 'postal_code': '94043', 'dma_code': 807, 'country_code': 'US', 'country_name': 'United States'}>>>if gir is not None:print(gir['country_code'])print(gir['country_code3'])print(gir['country_name'])print(gir['city'])print(gir['region'])print(gir['region_name'])print(gir['postal_code'])print(gir['latitude'])print(gir['longitude'])print(gir['area_code'])print(gir['time_zone'])print(gir['metro_code'])print(str(gir))>>> gir['country_code'],gir['city'],gir['region_name']('US', 'Mountain View', 'California')>>>注意:安装完成后,最好执行一次 /sbin/ldconfig,否则在import GeoIP时,可能会报:“ libGeoIP.so.1: cannot open shared object file: No such file or directory"默认libGeoIP.so.1的路径是 /usr/local/lib/libGeoIP.so.1,需要检查/etc/ld.so.conf文件中是否有包含:/usr/local/lib若没有,则加上此目录再/sbin/ldconfig。
0 0
- Python 安装 MaxMind GeoLite City
- nmap -- [ip-geolocation-maxmind]
- 持续集成工具 Team City的安装
- 持续集成工具 Team City的安装
- Geoip MaxMind DB 生成指南
- MaxMind GeoIP --- 通过IP地址获取地理信息
- 使用MaxMind 根据IP地址对访问者定位
- 使用MaxMind提供的ip地址查询功能
- 利用Nginx加GeoIP MaxMind数据库获取用户的地理位置
- 利用com.maxmind.db根据ip地址获取地理位置信息
- SparkStreaming maxmind-GeoLite2 第三方对象序列化问题
- REDWOOD CITY
- City hall
- ME & CITY
- City hall
- Dream City
- battle city
- City Horizon
- openvpn 连接提示CreateFile failed on TAP device
- iOS中UITabelView的层级结构
- Oracle SQL Developer相关
- UC技术博客开放通知
- 电商打折促销 ,忽悠 接着忽悠
- Python 安装 MaxMind GeoLite City
- 2014福布斯中国名人榜:范冰冰压刘德华居首
- 算法java实现--贪心算法--最小生成树问题--Prim算法
- ViewPager+Fragment 仅加载当前页面的demo
- 程序员编程艺术学习笔记(三)寻找最小的k个数
- leetcode 刷题指南
- iOS开发和学习中比较好用的学习资料
- 【转】我的成长磨练:每天写博客
- Android的Notification研究