I'm trying to find the Country name for the given IP address using the 'GeoIP2-City.mmdb' file.
Ex: IP: 24.171.221.56, I need to get 'Puerto Rico'. But this isn't working when I passed the IP address in a function.
ipa = ['24.171.221.56']
def country(ipa, reader):
try:
response = reader.city(ipa)
response = response.country.name
return response
except:
return 'NA'
country(ipa, reader=geoip2.database.Reader('GeoIP2-City.mmdb'))
'NA'
However, If I use the actual IP address in the function it is returning 'Puerto Rico'
ipa = ['24.171.221.56']
def country(ipa, reader):
try:
response = reader.city('24.171.221.56')
response = response.country.name
return response
except:
return 'NA'
country(ipa, reader=geoip2.database.Reader('GeoIP2-City.mmdb'))
'Puerto Rico'
Can someone help with this?