Skip to content

Instantly share code, notes, and snippets.

@kshwetabh
Created May 13, 2012 22:32
Show Gist options
  • Save kshwetabh/2690548 to your computer and use it in GitHub Desktop.
Save kshwetabh/2690548 to your computer and use it in GitHub Desktop.
A python snippet to retrieve the list of all the devices (computer, tablet, mobile, etc) connected currently with your router.
'''
Tested only with Linksys WRT54G Router. Not sure if it will work with other routers. You might need to modify the url and header according to your router.
I still need to further clean the output to retrieve the list/name of devices rather than complete HTML in the response.
'''
import urllib2
from BeautifulSoup import BeautifulSoup
url = 'http://192.168.1.1/DHCPTable.asp'
headers= {'Authorization':'Basic XXXXX-25_CHARACTER_TOKEN_GOES_HERE'}
#this token you can retrieve from the login response. Once you
#login into your router admin console, this token is appended to
#all the subsequent requests
request = urllib2.Request(url=url, headers={ 'Authorization' : 'Basic ' })
response = urllib2.urlopen(request)
b1 = response.read()
print b1 #Prints the DHCP table with all the systems connected to your router.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment