Skip to content

Instantly share code, notes, and snippets.

@aniline
Created November 1, 2016 16:32
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 aniline/8291f61fadcb4fd2412e2052845dcf5c to your computer and use it in GitHub Desktop.
Save aniline/8291f61fadcb4fd2412e2052845dcf5c to your computer and use it in GitHub Desktop.
Scrape status and stats page off d-link dir-615 hardware ver. T1 Firmware 20.07
#!/usr/bin/env python
#
# DLink DIR-615 HW:T1 FW:20.07 status.
from sys import argv, exit
import urllib as u1
import urllib2 as u2
import bs4
# Router IP
ip = '192.168.1.1'
p= { 'username' : '',
'password' : '',
'submit.htm?login.htm' : 'Send' }
try:
h = { 'Referer' : 'http://' + ip + ' /login.htm', 'Cookie' : 'SessionID=' }
f = u2.urlopen(u2.Request('http://' + ip + ' /stats.htm'));
stats_html = f.read()
f.close()
if (stats_html.find('parent.location="/login.htm"') != -1):
f = u2.urlopen(u2.Request('http://' + ip + ' /login.htm', headers={ 'Cookie' : 'SessionID=' }))
f.read()
f.close()
if (len(argv) < 2):
print 'Not loggedin: Use', argv[0], 'username'
exit(1)
p['username'] = argv[1]
p['password'] = __import__('getpass').getpass()
f = u2.urlopen(u2.Request('http://' + ip + ' /login.cgi', data=u1.urlencode(p), headers=h));
f.read()
f.close()
f = u2.urlopen(u2.Request('http://' + ip + ' /stats.htm', headers=h));
stats_html = f.read()
f.close()
f = u2.urlopen(u2.Request('http://' + ip + ' /status.htm', headers=h));
status_html = f.read()
f.close()
l = bs4.BeautifulSoup(status_html, 'lxml')
upt = l.find_all(id='body_header')[0].find_all('table')[0].find_all('tr')[1].find_all('td')[-1].get_text().strip()
l = bs4.BeautifulSoup(stats_html, 'lxml')
wan_stats = map (lambda x: x.get_text(), l.find_all('table')[-1].find_all('tr')[5].find_all('td'))
print 'Uptime', upt
print 'WAN STATS:',' '.join(wan_stats)
except Exception, e:
print "Error", e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment