Skip to content

Instantly share code, notes, and snippets.

@rashkur
Created November 5, 2015 18:40
Show Gist options
  • Save rashkur/297b3d9e4bb0e306594d to your computer and use it in GitHub Desktop.
Save rashkur/297b3d9e4bb0e306594d to your computer and use it in GitHub Desktop.
import urllib2, simplejson as json
manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
manager.add_password(None, 'https://robot-ws.your-server.de', 'login', 'password')
handler = urllib2.HTTPBasicAuthHandler(manager)
opener = urllib2.build_opener(handler)
def get_rdns(addr):
try:
rdns = opener.open('https://robot-ws.your-server.de/rdns/'+addr)
ipandreverse = json.load(rdns)
return ipandreverse["rdns"]["ip"]+" "+ipandreverse["rdns"]["ptr"]
except urllib2.HTTPError, error:
return addr
result = opener.open('https://robot-ws.your-server.de/server')
jsondata = json.load(result)
for k,v in enumerate(jsondata):
server = opener.open('https://robot-ws.your-server.de/server/'+v["server"]["server_ip"])
data = json.load(server)
tmp = data
for i,addr in enumerate(data["server"]["ip"]):
tmp["server"]["ip"][i] = get_rdns(addr)
print json.dumps(tmp, sort_keys=True, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment