0

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
RachelW
  • 1
  • 1

2 Answers2

0

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.

0

print(response.city.name) and print(response.traits.network)

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 21 '22 at 05:10