官网地址:http://dev.maxmind.com/geoip/geoip2/geolite2/#Databases
ubuntu 下安装很简单:
1. 安装geoip的py 库
sudo pip install pygeoip
2 下载 GeoLiteCity.dat
使用:
import pygeoip
gi = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.MEMORY_CACHE)
location = gi.record_by_addr(8.8.8.8)
print location
>>> {'city': '', 'region_name': '', 'area_code': 0, 'time_zone': '', 'dma_code': 0, 'metro_code': None, 'country_code3': 'USA', 'latitude': 38.0, 'postal_code': '', 'longitude': -97.0, 'country_code': 'US', 'country