Created
September 10, 2013 15:17
-
-
Save andygock/6510935 to your computer and use it in GitHub Desktop.
Rip ADSL statistics from D-Link ADSL router DSL-2870B with firmware 2.00.01 ## Example of usage $ python dlink_stats.py Logging in... Getting device info... DSL is connected! Getting stats... DSL Statistics: up_attaintable_rate 388000 down_attaintable_rate 8004000 down_data_rate 6214000 up_data_rate 350000
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
#!python | |
# | |
# D-Link Router Stats Ripper | |
# | |
# For D-Link DSL-2870B | |
# Firmware 2.00.01 | |
import httplib, urllib, re, StringIO, sys, hashlib | |
modem_username = "admin" | |
modem_password = "YOUR PASSWORD" | |
# Generate hashes for user/pass login | |
md5 = hashlib.md5() | |
md5.update(modem_username) | |
hash_user = md5.hexdigest() | |
md5.update(modem_password) | |
hash_pass = md5.hexdigest() | |
# POST variables | |
params = urllib.urlencode({ | |
'f_username': hash_user, | |
'f_password': hash_pass, | |
'submit-url': "/index.htm" | |
}) | |
headers = { | |
#"Content-type": "application/x-www-form-urlencoded", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Accept-Encoding": "gzip, deflate", | |
"Accept-Language": "en-US,en;q=0.5", | |
"Connection": "keep-alive", | |
"Host": "192.168.1.1", | |
"Referer": "http://192.168.1.1/login.htm", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0 FirePHP/0.7.4" | |
} | |
conn = httplib.HTTPConnection("192.168.1.1:80") | |
# Log on! | |
print "Logging in..." | |
conn.request( | |
"POST", | |
"/login.htm", | |
params, | |
headers | |
) | |
response = conn.getresponse() | |
#print "POST Login" | |
#print response.status, response.reason | |
data = response.read() | |
data = data.split("\n") | |
logged_in = False | |
for line in data: | |
match = re.match(r'.*/STATUS/st_deviceinfo\.htm.*',line) | |
#print line | |
if (match): | |
logged_in = True | |
break | |
if not logged_in: | |
print "Login failed" | |
sys.exit() | |
# Get device info | |
# Find out if DSL is connected | |
print "Getting device info..." | |
conn.request("GET","/STATUS/st_deviceinfo.htm") | |
response = conn.getresponse() | |
#print "GET /STATUS/st_deviceinfo.htm" | |
#print response.status, response.reason | |
data = response.read() | |
data = data.split("\n") | |
connected = False | |
for line in data: | |
match = re.match(r'.* \[\[\"connected\"\].*',line) | |
if match: | |
connected = True | |
#print line | |
if connected: | |
print "DSL is connected!" | |
else: | |
print "DSL is not connected!" | |
sys.exit(); | |
# Get stats | |
# Find out the up an downstream rates | |
print "Getting stats..." | |
conn.request("GET","/STATUS/st_stat.htm?0") | |
response = conn.getresponse() | |
#print "GET /STATUS/st_stat.htm?0" | |
#print response.status, response.reason | |
data = response.read() | |
data = data.split("\n") | |
stats = {} | |
for line in data: | |
match = re.match(r'^var downLists=\[.*\"(\d+)\",\"(\d+)\"\];$',line) | |
if match: | |
stats['down_data_rate'] = match.group(1) | |
stats['down_attaintable_rate'] = match.group(2) | |
match = re.match(r'^var upLists=\[.*\"(\d+)\",\"(\d+)\"\];$',line) | |
if match: | |
stats['up_data_rate'] = match.group(1) | |
stats['up_attaintable_rate'] = match.group(2) | |
# Display stats to console | |
print "" | |
print "DSL Statistics:" | |
for key in stats: | |
print key, stats[key] | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script is a bit useless, it's much better to use netcat or a shell script to communicate via telnet interface.