Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Created July 14, 2014 22:30
Show Gist options
  • Select an option

  • Save Ironholds/ca46d5ef1d6acfbe5097 to your computer and use it in GitHub Desktop.

Select an option

Save Ironholds/ca46d5ef1d6acfbe5097 to your computer and use it in GitHub Desktop.
def country(x):
#Read in files, storing in memory for speed
ip4_geo = pygeoip.GeoIP(filename = sys.argv[4], flags = 1)
ip6_geo = pygeoip.GeoIP(filename = sys.argv[5], flags = 1)
#Check type
x = listcheck(x)
#Construct output list
output_list = range(len(x))
#For each entry in the input list, retrieve the country code and add it to the output object
for i in range(len(x)):
if(bool(re.search(":",x[i]))):
output_list[i] = ip6_geo.country_code_by_addr(x[i])
else:
output_list[i] = ip4_geo.country_code_by_addr(x[i])
#Return
return output_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment