Created
April 10, 2012 11:12
-
-
Save overplumbum/2350535 to your computer and use it in GitHub Desktop.
NetGear WiFi Router Monitoring
This file contains 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
#!/usr/bin/env python | |
import urllib2, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-H', required=True) | |
parser.add_argument('-U', default='admin') | |
parser.add_argument('-P', default='password') | |
args = parser.parse_args() | |
fields = "an_rxbs an_txbs bgn_rxbs bgn_txbs lan_rxbs lan_txbs".split(' ') | |
realm = None | |
try: | |
urllib2.urlopen('http://' + args.H) | |
assert False, "unexpected http response" | |
except urllib2.HTTPError as e: | |
realm = e.headers['WWW-Authenticate'].split('=', 1)[1].strip('"') | |
url = 'http://{0}/RST_statistic.htm'.format(args.H) | |
auth_handler = urllib2.HTTPBasicAuthHandler() | |
auth_handler.add_password(realm, url, args.U, args.P) | |
opener = urllib2.build_opener(auth_handler) | |
lines = opener.open(url).read().splitlines() | |
d = [tuple(line.split(' ', 1)[1].rstrip(';').split('=', 1)) for line in lines if line.startswith('var ')] | |
d = [(k.rstrip(), v.strip().strip('"')) for k, v in d] | |
d = [(k, (int(v) if v.isdigit() else v)) for k, v in d if k in fields] | |
d = dict(d) | |
d = list(sorted(d.items())) | |
import simplejson as json | |
print json.dumps(dict(d), indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment