dnsleases pimped - output sorted by hostname + ipx
This commit is contained in:
parent
ecce458caa
commit
79dc87c707
24
dnsleases
24
dnsleases
@ -12,8 +12,13 @@ class host(object):
|
|||||||
self.hostname = ''
|
self.hostname = ''
|
||||||
self.lease_tm = 0
|
self.lease_tm = 0
|
||||||
|
|
||||||
|
def sortcriteria(h):
|
||||||
|
rv = h.hostname if h.hostname != '*' else '~'
|
||||||
|
rv += ".".join(["%03d" % int(v) for v in h.ip.split('.')])
|
||||||
|
return rv.lower()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%-16s - %17s - %-10s - %15s - %s" % (self.ip, self.mac, self.state, time.asctime(time.localtime(self.lease_tm)), self.hostname)
|
return " * %-16s - %17s - %-10s - %15s - %s" % (self.ip, self.mac, self.state, time.asctime(time.localtime(self.lease_tm)), self.hostname)
|
||||||
|
|
||||||
|
|
||||||
class hostlist(dict):
|
class hostlist(dict):
|
||||||
@ -27,10 +32,19 @@ class hostlist(dict):
|
|||||||
else:
|
else:
|
||||||
self[host.mac] = host
|
self[host.mac] = host
|
||||||
|
|
||||||
|
def vlan_list(self, vlan):
|
||||||
|
rv = hostlist()
|
||||||
|
for h in self.values():
|
||||||
|
if h.vlan == vlan:
|
||||||
|
rv.append(h)
|
||||||
|
return rv
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
entries = list(self.values())
|
||||||
|
entries.sort(key=host.sortcriteria)
|
||||||
rv = ""
|
rv = ""
|
||||||
for key in self:
|
for h in entries:
|
||||||
rv += str(self[key]) + '\n'
|
rv += str(h) + '\n'
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +89,5 @@ with open('/var/lib/misc/dnsmasq.leases', 'r') as fh:
|
|||||||
|
|
||||||
for vlan in [20, 30, 40, 50, 60, 90]:
|
for vlan in [20, 30, 40, 50, 60, 90]:
|
||||||
print("Hosts in VLAN %d" % vlan)
|
print("Hosts in VLAN %d" % vlan)
|
||||||
for host in hl.values():
|
print(hl.vlan_list(vlan))
|
||||||
if host.vlan == vlan:
|
|
||||||
print(" *", host)
|
|
||||||
print()
|
print()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user