Browse Source

dnsleases pimped - output sorted by hostname + ipx

84582af
Dirk Alders 1 year ago
parent
commit
79dc87c707
1 changed files with 18 additions and 6 deletions
  1. 18
    6
      dnsleases

+ 18
- 6
dnsleases View File

12
         self.hostname = ''
12
         self.hostname = ''
13
         self.lease_tm = 0
13
         self.lease_tm = 0
14
 
14
 
15
+    def sortcriteria(h):
16
+        rv = h.hostname if h.hostname != '*' else '~'
17
+        rv += ".".join(["%03d" % int(v) for v in h.ip.split('.')])
18
+        return rv.lower()
19
+
15
     def __str__(self):
20
     def __str__(self):
16
-        return "%-16s - %17s - %-10s - %15s - %s" % (self.ip, self.mac, self.state, time.asctime(time.localtime(self.lease_tm)), self.hostname)
21
+        return "  * %-16s - %17s - %-10s - %15s - %s" % (self.ip, self.mac, self.state, time.asctime(time.localtime(self.lease_tm)), self.hostname)
17
 
22
 
18
 
23
 
19
 class hostlist(dict):
24
 class hostlist(dict):
27
         else:
32
         else:
28
             self[host.mac] = host
33
             self[host.mac] = host
29
 
34
 
35
+    def vlan_list(self, vlan):
36
+        rv = hostlist()
37
+        for h in self.values():
38
+            if h.vlan == vlan:
39
+                rv.append(h)
40
+        return rv
41
+
30
     def __str__(self):
42
     def __str__(self):
43
+        entries = list(self.values())
44
+        entries.sort(key=host.sortcriteria)
31
         rv = ""
45
         rv = ""
32
-        for key in self:
33
-            rv += str(self[key]) + '\n'
46
+        for h in entries:
47
+            rv += str(h) + '\n'
34
         return rv
48
         return rv
35
 
49
 
36
 
50
 
75
 
89
 
76
 for vlan in [20, 30, 40, 50, 60, 90]:
90
 for vlan in [20, 30, 40, 50, 60, 90]:
77
     print("Hosts in VLAN %d" % vlan)
91
     print("Hosts in VLAN %d" % vlan)
78
-    for host in hl.values():
79
-        if host.vlan == vlan:
80
-            print("  *", host)
92
+    print(hl.vlan_list(vlan))
81
     print()
93
     print()

Loading…
Cancel
Save