Created
June 27, 2020 14:12
-
-
Save frozenpandaman/acca39d3fe0342691b5e3ee2ae9c68cf to your computer and use it in GitHub Desktop.
translate a list of IPs to a list of location coordinates
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
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