通过IP访问国家的离线工具
ip-countr的Python项目详细描述
通过IP获取国家信息的离线工具
要求
- python=3.6
- IP2Location™Lite IP-Country-Region-City数据库
安装
- 从下载ip2location数据库 https://lite.ip2location.com/database/ip-country-region-city
- 安装库:
pip install ip_country
用法
>>> from pprint import pprint >>> from ip_country import IPCountry >>> ip = IPCountry('/path/to/ipdb.csv') >>> ip_data = ip.get_ip_data('13.73.96.0') >>> pprint(ip_data) {'city_name': 'Melbourne', 'country_code': 'AU', 'country_name': 'Australia', 'error': None, 'ip': '13.73.96.0', 'region_name': 'Victoria'} >>> ip_data = ip.get_ip_data('blah.73.96.0') >>> pprint(ip_data) {'error': "Only decimal digits permitted in 'blah' in 'blah.73.96.0'", 'ip': 'blah.73.96.0'}