Skip to content

Instantly share code, notes, and snippets.

@frozenpandaman
Created June 27, 2020 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozenpandaman/acca39d3fe0342691b5e3ee2ae9c68cf to your computer and use it in GitHub Desktop.
Save frozenpandaman/acca39d3fe0342691b5e3ee2ae9c68cf to your computer and use it in GitHub Desktop.
translate a list of IPs to a list of location coordinates
import geoip2.database
# https://dev.maxmind.com/geoip/geoip2/geolite2/
reader = geoip2.database.Reader('GeoLite2-City.mmdb')
locs = open("locs.txt").read().splitlines() # in - list of IPs, one per line
latlongs = [] # out
count = 1
for ip in locs:
response = reader.city(ip)
result = str(response.location.latitude) + ", " + str(response.location.longitude)
latlongs.append(result)
print("processed {}".format(count))
count += 1
with open('result-latlongs.txt', 'w') as f:
for item in latlongs:
f.write("{}\n".format(item))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment