Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created September 18, 2011 05:53
Show Gist options
  • Save shreyansb/1224785 to your computer and use it in GitHub Desktop.
Save shreyansb/1224785 to your computer and use it in GitHub Desktop.
Get a list of MAC addresses that have connected to your router. Most recent first.
import os
import re
import datetime
def get_connections():
curl_cmd = "curl -s -u username:password http://192.168.1.1/Log_View.asp | grep 'received REQUEST'"
# TODO replace with subprocess.Popen()
resp = os.popen4(curl_cmd)[1].read()
resp = resp.split('\n')
connections = []
for r in resp:
m = re.match('^.*DDD\(\'(.*) received REQUEST from (.*)\'\).*$', r)
if m:
# sample_dt = 'Sun, 18 Sep 2011 02:43:09'
dt = datetime.datetime.strptime(m.group(1), '%a, %d %b %Y %H:%M:%S')
connections.append((dt, m.group(2)))
connections.sort(key = lambda x: x[0], reverse=True)
print connections
if __name__ == '__main__':
get_connections()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment