Jul
22
2022
python-geoip实现IP定位
pip3 install python-geoip-python3 pip3 install python-geoip-geolite2
使用
from geoip import geolite2
match = geolite2.lookup('218.81.244.122')
match is not None
match.location
match.country
pip3 install geoip2
import geoip2.database
reader=geoip2.database.Reader('/home/geoipupdate_4.8.0_linux_amd64/GeoLite2-City.mmdb')
ipinfo=reader.city(ip)
定时更新数据库
https://dev.maxmind.com/geoip/geolite2-free-geolocation-data
步骤
1.注册登录
2.获取AccountID和LicenseKey
3.修改
vim /etc/GeoIP.conf
微信扫一扫,打赏作者吧~
最活跃的读者