Mercurial > code > home > repos > homeauto
comparison 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 |
comparison
equal
deleted
inserted
replaced
866:a99b4d5afb83 | 867:d9bc9a82dcca |
---|---|
1 def addDhcpData(rows): | |
2 """given dicts with 'mac', add other data from the dhcp cache""" | |
3 currentLease = None | |
4 for line in open('/var/lib/dhcp/dhcpd.leases'): | |
5 if line.startswith('lease '): | |
6 currentLease = {'ip': line.split()[1]} | |
7 elif line.startswith(' hardware ethernet '): | |
8 currentLease['mac'] = line.split()[2].strip(';').upper() | |
9 elif line.startswith(' client-hostname'): | |
10 currentLease['clientHostname'] = line.split(None, 2)[1].strip('";') | |
11 elif line.startswith(' binding state'): | |
12 currentLease['bindingState'] = line.split()[2].strip(';') | |
13 elif line.startswith('}'): | |
14 if currentLease.get('bindingState') == 'active': | |
15 # there seem to be a lot of 'active' blocks | |
16 # for the same ip addr and mac. I haven't | |
17 # looked into whether they hold different | |
18 # lease terms or what | |
19 for r in rows: | |
20 if r['mac'] == currentLease['mac']: | |
21 r.update(currentLease) | |
22 | |
23 |