这是我一次获得一个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
将所有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读取到列表中,然后再次迭代它们。
print(response.city.name(和print(wend.traits.network(