Skip to content

Instantly share code, notes, and snippets.

@emileaben
Created November 8, 2018 15:19
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 emileaben/e2af6bc456a598c44a84ab760913d19f to your computer and use it in GitHub Desktop.
Save emileaben/e2af6bc456a598c44a84ab760913d19f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import requests
import time
ips = set()
for line in sys.stdin:
# assume its well formed
line = line.rstrip('\n')
ips.add( line )
bobross_url = "https://ipmap.ripe.net/api/v1/locate/all/?resources=%s" % (",".join( ips ) ,)
r = requests.get( bobross_url )
#time.sleep( len( ips ) ) # TODO some formula for this
# now fetch
for ip in ips:
skeletor_url = "https://ipmap.ripe.net/api/v1/locate/%s/partials/single-radius" % ( ip )
r = requests.get( skeletor_url )
locs = r.json()["partials"][0]["locations"]
if len( locs ) > 0:
print "%s %s" % (ip, r.json()["partials"][0]["locations"][0])
else:
print "%s NULL" % (ip, )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment