DHCPD Leasezähler af Python 3 aktualisiert
parent
1844652e4d
commit
baf76b3517
|
@ -1,14 +1,33 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Zähle aktive DHCP-Leases
|
||||||
|
|
||||||
# Vergleiche
|
Vergleiche dazu:
|
||||||
# dhcp-lease-list --lease /var/lib/dhcp/dhcpd.leases
|
dhcp-lease-list --lease /var/lib/dhcp/dhcpd.leases
|
||||||
|
|
||||||
|
Änderungsprotokoll
|
||||||
|
==================
|
||||||
|
|
||||||
|
Version Datum Änderung(en) von
|
||||||
|
-------- ----------- ------------------------------------------------------ ----
|
||||||
|
1.0 ?
|
||||||
|
1.1 2017-01-29 tho
|
||||||
|
2.0 2023-12-06 Umstellung auf Python 3 tho
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
__author__ = "Thomas Hooge"
|
||||||
|
__copyright__ = "Public Domain"
|
||||||
|
__version__ = "2.0"
|
||||||
|
__email__ = "thomas@hoogi.de"
|
||||||
|
__status__ = "Development"
|
||||||
|
|
||||||
def count_dhcp_leases():
|
def count_dhcp_leases():
|
||||||
regex_leaseblock = re.compile(r"lease (?P<ip>\d+\.\d+\.\d+\.\d+) {(?P<config>[\s\S]+?)\n}")
|
regex_leaseblock = re.compile(r"lease (?P<ip>\d+\.\d+\.\d+\.\d+) {(?P<config>[\s\S]+?)\n}")
|
||||||
regex_properties = re.compile(r"\s+(?P<key>\S+) (?P<value>[\s\S]+?);")
|
regex_properties = re.compile(r"\s+(?P<key>\S+) (?P<value>[\s\S]+?);")
|
||||||
|
@ -26,12 +45,13 @@ def count_dhcp_leases():
|
||||||
return leases
|
return leases
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "DHCP leases counter"
|
print("DHCP leases counter")
|
||||||
print "Version 1.1"
|
print("Version {}".format(__version__))
|
||||||
print
|
print()
|
||||||
print "Options"
|
print("Options")
|
||||||
print " -n numeric output only"
|
print(" -h show this help")
|
||||||
print
|
print(" -n numeric output only")
|
||||||
|
print()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
@ -39,8 +59,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "nh", ["help"])
|
opts, args = getopt.gnu_getopt(sys.argv[1:], "nh", ["help"])
|
||||||
except getopt.GetoptError, err:
|
except getopt.GetoptError as err:
|
||||||
print str(err)
|
print(str(err))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt in ("-h", "--help"):
|
if opt in ("-h", "--help"):
|
||||||
|
@ -51,6 +71,6 @@ if __name__ == "__main__":
|
||||||
break
|
break
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print "%d unique active leases" % count_dhcp_leases()
|
print("%d unique active leases" % count_dhcp_leases())
|
||||||
else:
|
else:
|
||||||
print count_dhcp_leases()
|
print(count_dhcp_leases())
|
||||||
|
|
Loading…
Reference in New Issue