comparison service/tomatoWifi/dhcpparse.py @ 62:f8cc3d1baa85

redo wifi scraper to work with zyxel router report page too. add last connected time (from mongo) to web table Ignore-this: 18bade72e14d40532bd019791d03fa7d
author drewp@bigasterisk.com
date Sat, 06 Apr 2013 17:08:19 -0700
parents
children
comparison
equal deleted inserted replaced
61:1afb0564636d 62:f8cc3d1baa85
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