#!/usr/bin/python
import urllib,urllib2,random, httplib
import cookielib
import socket
router = "https://10.31.31.1"
username = "admin"
password = "yourpassword"
timeout = 20
socket.setdefaulttimeout(timeout)
try:
req = urllib2.Request(router)
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, router, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
fd = opener.open(req)
print "\t\n\n[+] Login successful: Username:",username,"Password:",password,"\n"
#change the mac address for the router WRT54G
changeMacUrl = router + "/apply.cgi"
parameters = {
'submit_button' : 'WanMAC',
'change_action' : '',
'submit_type' : '',
'action' : 'Apply',
'mac_clone_enable' : '1',
'def_hwaddr' : '6',
'def_hwaddr_0' : '00',
'def_hwaddr_1' : '16',
'def_hwaddr_2' : '3e',
'def_hwaddr_3' : "%02x" % random.randint(0x00, 0x7f),
'def_hwaddr_4' : "%02x" % random.randint(0x00, 0xff),
'def_hwaddr_5' : "%02x" % random.randint(0x00, 0xff)
}
txdata = urllib.urlencode(parameters)
txheaders = {
'User-agent' : 'Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding':'gzip,deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive': '115',
'Connection': 'keep-alive',
'Referer': router+'/WanMAC.asp',
'Content-Type': 'application/x-www-form-urlencoded'
}
print txdata
req = urllib2.Request(changeMacUrl, txdata, txheaders)
response = opener.open(req)
#the_page = response.read()
#print the_page
exit(0)
except urllib2.HTTPError, e:
print "HTTPError", e
except urllib2.URLError, e:
print "URLError", e.reason