Manipulate your wireless router using Python

Here below I just give a thread about how to manipulate your wireless router by refresh/read/delete logs. I think you could do more things than this. As the theory is the same.
This scipt can be used for monitoring who else is using the network doing what now if you find your WoW is lagged so much 🙂

There is a wireless router I connected is a NetGear WGR614v7. After accessing the adminstation page, we can find that it is a very simple web page. so we could use the common webpage crawling way to deal with it.

Actually the script I pasted below is a guide for how to deal with the Basic Authentication of HTTP and some use of lxml and re:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @author: Sean Wang,
# target router type: NetGear, WGR614v7
from __future__ import unicode_literals
import urllib2
import re
import lxml.html as lh

rooturl='' # admin url of the router
username = 'admin'
password = 'password'

# create a urllib2 opener for basic authentication
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, rooturl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)

#get self ip
devhandle= urllib2.urlopen(rooturl+'/DEV_device.htm')
devdoc= lh.document_fromstring(devcontent)
devs=[i.text_content() for i in devdoc.xpath("//span")]
devs=zip(*[devs[i::4] for i in xrange(1,4)])
for i in devs[1:]:
    if 'fclef' in i[1].lower(): # fclef is my computer name

#refresh log, a post method

#get log
pagehandle = urllib2.urlopen(rooturl+'/fwLog.cgi')
ptn=re.compile('^\[(.+): (.+)\] Source: ([0-9\.]{11,15})')
for i in [i for i in logs.split('\r\n') if i]:,i).groups()
    if loginfo[2] not in myips:
        print '{0[2]}({1}) {0[0]} {0[1]}'.format(loginfo,othernames.get(loginfo[2]))

#clear log

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s