Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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