Share Pastebin
Guest
Public paste!

#change the mac address for the router WRT54G

By: a guest | May 29th, 2010 | Syntax: Python | Size: 1.97 KB | Hits: 226 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/python
  2.  
  3. import urllib,urllib2,random, httplib
  4. import cookielib
  5. import socket
  6.  
  7. router = "https://10.31.31.1"
  8. username = "admin"
  9. password = "yourpassword"
  10.  
  11. timeout = 20
  12. socket.setdefaulttimeout(timeout)
  13.  
  14. try:
  15.         req = urllib2.Request(router)
  16.         passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
  17.         passman.add_password(None, router, username, password)
  18.  
  19.         authhandler = urllib2.HTTPBasicAuthHandler(passman)
  20.         opener = urllib2.build_opener(authhandler)
  21.         fd = opener.open(req)
  22.         print "\t\n\n[+] Login successful: Username:",username,"Password:",password,"\n"                       
  23.        
  24.         #change the mac address for the router WRT54G
  25.         changeMacUrl = router + "/apply.cgi"
  26.         parameters = {
  27.                                                                 'submit_button' : 'WanMAC',
  28.                                                                 'change_action' : '',
  29.                                                                 'submit_type' : '',
  30.                                                                 'action' : 'Apply',
  31.                                                                 'mac_clone_enable' : '1',
  32.                                                                 'def_hwaddr' : '6',
  33.                                                                 'def_hwaddr_0' : '00',
  34.                                                                 'def_hwaddr_1' : '16',
  35.                                                                 'def_hwaddr_2' : '3e',
  36.                                                                 'def_hwaddr_3' : "%02x" % random.randint(0x00, 0x7f),
  37.                                                                 'def_hwaddr_4' : "%02x" % random.randint(0x00, 0xff),
  38.                                                                 'def_hwaddr_5' : "%02x" % random.randint(0x00, 0xff)
  39.                                                         }      
  40.         txdata = urllib.urlencode(parameters)
  41.         txheaders = {  
  42.                 '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',
  43.                 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  44.                 'Accept-Language': 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3',
  45.                 'Accept-Encoding':'gzip,deflate',
  46.                 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  47.                 'Keep-Alive': '115',
  48.                 'Connection': 'keep-alive',
  49.                 'Referer': router+'/WanMAC.asp',
  50.                 'Content-Type': 'application/x-www-form-urlencoded'
  51.         }
  52.  
  53.         print txdata
  54.        
  55.         req = urllib2.Request(changeMacUrl, txdata, txheaders)
  56.         response = opener.open(req)
  57.         #the_page = response.read()
  58.         #print the_page
  59.  
  60.         exit(0)
  61. except urllib2.HTTPError, e:
  62.         print "HTTPError", e
  63. except urllib2.URLError, e:
  64.         print "URLError", e.reason