Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created February 9, 2013 16:14
Show Gist options
  • Save 0xKD/4745862 to your computer and use it in GitHub Desktop.
Save 0xKD/4745862 to your computer and use it in GitHub Desktop.
Block a MAC address on the D-Link DSL-2750U
# 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