Created
February 9, 2013 16:14
-
-
Save 0xKD/4745862 to your computer and use it in GitHub Desktop.
Block a MAC address on the D-Link DSL-2750U
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
# Block a specific MAC address on the D-Link DSL-2750U (using parental control). | |
# May also work for other/similar D-Link routers (eg; 27xx) | |
import urllib,urllib2 | |
import random,json,re | |
import base64 | |
# Modify as necessary | |
login = base64.b64encode('admin:password') # username:password | |
mac = '00:00:00:00:00:00' # MAC address to block in the form xx:xx:xx:xx:xx:xx | |
router_ip = '192.168.1.1' # Your router's IP address | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
'Authorization': 'Basic '+login, | |
'Referer': 'http://192.168.1.1/todadd.html' | |
} | |
params = { | |
'action':'add', | |
'username':str(random.random()*10000)[0:4], | |
'mac':mac,'days':'127', | |
'start_time':'0','end_time':'1440', | |
'sessionKey':'' | |
} | |
# Get the sessionKey | |
furl = 'http://'+router_ip+'/todadd.html' | |
freq = urllib2.Request(furl,None,headers) | |
fhtml = urllib2.urlopen(freq).read() | |
regex = re.compile("=\d+") | |
sessionKey = regex.findall(fhtml)[0][1:] | |
params['sessionKey'] = sessionKey | |
url = 'http://'+router_ip+'/todmngr.tod' | |
req = urllib2.Request(url+'?'+urllib.urlencode(params).replace('%3A',':'),None,headers) | |
code = urllib2.urlopen(req) | |
respheaders = code.info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment