Reputation: 1
This is how I've been getting the country name for one IP address at a time, but I need to be able to do multiple, sometimes over 50 at a time.
>>>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
Upvotes: 0
Views: 259
Reputation: 144
put all the ip's to a list and iterate through the list.
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
or add the ip's to an excel sheet and use pandas or xlrd to read the ip's to a list and iterate them again as shown above.
Upvotes: 0