Created
July 14, 2014 22:30
-
-
Save Ironholds/ca46d5ef1d6acfbe5097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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