From 9e1357ddc21149549f8de4e106693ee98d8da213 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 29 Jan 2017 11:18:55 +0100 Subject: [PATCH] =?UTF-8?q?Kommandozeilenoptionen=20f=C3=BCr=20dhcpd-lease?= =?UTF-8?q?s=20eingebaut,=20optional=20nur=20numerische=20Ausgabe=20m?= =?UTF-8?q?=C3=B6glich=20(f=C3=BCr=20Scriptverwendung)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dhcpd-leases.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/dhcpd-leases.py b/dhcpd-leases.py index a0d8f5d..7e3f2fb 100755 --- a/dhcpd-leases.py +++ b/dhcpd-leases.py @@ -1,8 +1,11 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- # Vergleiche # dhcp-lease-list --lease /var/lib/dhcp/dhcpd.leases +import sys +import getopt import re import datetime @@ -22,5 +25,32 @@ def count_dhcp_leases(): leases = len(macs) return leases +def usage(): + print "DHCP leases counter" + print "Version 1.1" + print + print "Options" + print " -n numeric output only" + print + if __name__ == "__main__": - print "%d unique active leases" % count_dhcp_leases() + + verbose = True + + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], "nh", ["help"]) + except getopt.GetoptError, err: + print str(err) + sys.exit(2) + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(1) + elif opt in ("-n"): + verbose = False + break + + if verbose: + print "%d unique active leases" % count_dhcp_leases() + else: + print count_dhcp_leases()