0

这就是我一次获得一个 IP 地址的国家名称的方式,但我需要能够做多个,有时一次超过 50 个。

>>>import geoip2.database
>>>
>>>reader = geoip2.database.Reader('/path/to/GeoLite2-City.mmdb')
>>>
>>>response = reader.city('128.101.101.101')
>>>
>>>response.country.iso_code
>>>
>>>response.country.name
4

1 回答 1

0

将所有 ip 放入一个列表并遍历该列表。

reader = geoip2.database.Reader('/path/to/GeoLite2-City.mmdb')
ip_list=['128.101.101.101','198.101.101.101','208.101.101.101','120.101.101.101','129.101.101.101','138.101.101.101','148.101.101.101']
for ip in ip_list:
    response = reader.city(ip)
    print response.country.iso_code
    print response.country.name

或将 ip 添加到 excel 表中,然后使用 pandas 或 xlrd 将 ip 读取到列表中并再次迭代它们,如上所示。

于 2017-06-23T19:24:29.173 回答