我的博客:https://blog.csdn.net/fengbohello/article/details/121611389
下载 IP2Location 模块
wget https://github.com/chrislim2888/IP2Location-Python/archive/master.zip
解压 & install IP2Location
unzip IP2Location-Python-master.zip
cd IP2Location-Python-master
python setup.py install
代码演示
# https://www.ip2location.com/development-libraries/ip2location/python
import IP2Location, os
'''
Cache the database into memory to accelerate lookup speed.
WARNING: Please make sure your system have sufficient RAM to use this feature.
'''
# database = IP2Location.IP2Location(os.path.join("data", "IPV6-COUNTRY.BIN"), "SHARED_MEMORY")
database = IP2Location.IP2Location(os.path.join("data", "IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-SAMPLE.BIN"))
rec = database.get_all("19.5.10.1")
print rec.country_short
print rec.country_long
print rec.region
print rec.city
print rec.isp
print rec.latitude
print rec.longitude
print rec.domain
print rec.zipcode
print rec.timezone
print rec.netspeed
print rec.idd_code
print rec.area_code
print rec.weather_code
print rec.weather_name
print rec.mcc
print rec.mnc
print rec.mobile_brand
print rec.elevation
print rec.usage_type
print rec.address_type
print rec.category