It was around 3:00 a.m. and I was supposed to be working on a paper – instead I was lurking on reddit like usual. Well I got an email from some random guy I didn’t know. He started off with asking me if I could help secure his router. So I showed him him how to set up WPA encryption on his specific router. Well he didn’t like that because according to him he didn’t want “those people” to know he knew they were accessing his internet. So then he asked how he could see who is on his internet. So I promptly lead him to the DHCP table on his routers configuration menu. He said this was too challenging and said he would pay me $30 for a program to do it and I had three days. So I told him I would do it for $60 in three hours. He went for it.
So I start messing around with some code and think of how I am going to do it. I started programming some sockets calls and C and was just going to connect and then just go ahead and send over a GET request then put it into an array and parse the valuable information ( in this case it was the mac address and the device name). Well about thirty minutes in I was getting annoyed. I blame the terrible combination of sleep deprivation and time restraints. So I saved what code I had for later use and started to make it in Python. Well short story short I made it in Python in no time. It isn’t the ideal solution but it works and that’s all he cared about. His type of router was a WRT400N.
# DHCP Table POP
# Requests device name + mac address
# LogicKills.org
# Made for *****1979@yahoo.com (you creepy bastard)
# 5/4/2010
#blah blah imports
import urllib
import re
import json
#define username and password (he wanted to keep his default fml)
password = "admin"
user = "admin"
#combines credentials with URL. Yes I hardcoded the URL, suck it.
website = urllib.urlopen("http://" + user + ":" + password + "@192.168.1.1/Static_dhcp.htm")
#looks for the fragment of code that stores DHCP clients
for lines in website.readlines():
if re.match("var myData", lines):
clients = lines
#cleans up the json object
clients = clients.strip("var myData = ")
clients = clients.replace(';','')
#loads json object
jsonList = json.loads(clients)
for x in jsonList:
print x[0] + " " + x[3]

