Mercurial > code > home > repos > homeauto
diff service/tomatoWifi/dhcpparse.py @ 867:d9bc9a82dcca
redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table
Ignore-this: 18bade72e14d40532bd019791d03fa7d
darcs-hash:20130407000819-312f9-6b262edf71421b17947050e80560005d7bffa80b
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 06 Apr 2013 17:08:19 -0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/tomatoWifi/dhcpparse.py Sat Apr 06 17:08:19 2013 -0700 @@ -0,0 +1,23 @@ +def addDhcpData(rows): + """given dicts with 'mac', add other data from the dhcp cache""" + currentLease = None + for line in open('/var/lib/dhcp/dhcpd.leases'): + if line.startswith('lease '): + currentLease = {'ip': line.split()[1]} + elif line.startswith(' hardware ethernet '): + currentLease['mac'] = line.split()[2].strip(';').upper() + elif line.startswith(' client-hostname'): + currentLease['clientHostname'] = line.split(None, 2)[1].strip('";') + elif line.startswith(' binding state'): + currentLease['bindingState'] = line.split()[2].strip(';') + elif line.startswith('}'): + if currentLease.get('bindingState') == 'active': + # there seem to be a lot of 'active' blocks + # for the same ip addr and mac. I haven't + # looked into whether they hold different + # lease terms or what + for r in rows: + if r['mac'] == currentLease['mac']: + r.update(currentLease) + +