From 327c6b0ebd5aad21437afa625fff484023957de5 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 10 Sep 2023 19:13:33 +0200 Subject: [PATCH 1/4] dnsleases added --- dnsleases | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 dnsleases diff --git a/dnsleases b/dnsleases new file mode 100755 index 0000000..ad8c243 --- /dev/null +++ b/dnsleases @@ -0,0 +1,14 @@ +#!/bin/bash + +LEASES_FILE=/var/lib/misc/dnsmasq.leases + +print_vlan() +{ + echo "Hosts in VLAN $1" + grep 192.168.$1. $LEASES_FILE | sed 's/^/ * /' +} + +for vl in 20 30 40 50 60 90 +do + print_vlan $vl +done From ecce458caaf09c6f4fc2656077d70f8587d81cbc Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Mon, 11 Sep 2023 20:48:25 +0200 Subject: [PATCH 2/4] dnsleases pimped - joined output of leases file and ip nx --- dnsleases | 89 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/dnsleases b/dnsleases index ad8c243..41273e9 100755 --- a/dnsleases +++ b/dnsleases @@ -1,14 +1,81 @@ -#!/bin/bash +#!/bin/python3 +# +import subprocess +import time -LEASES_FILE=/var/lib/misc/dnsmasq.leases +class host(object): + def __init__(self): + self.mac = '' + self.ip = '' + self.vlan = 0 + self.state = '' + self.hostname = '' + self.lease_tm = 0 -print_vlan() -{ - echo "Hosts in VLAN $1" - grep 192.168.$1. $LEASES_FILE | sed 's/^/ * /' -} + def __str__(self): + return "%-16s - %17s - %-10s - %15s - %s" % (self.ip, self.mac, self.state, time.asctime(time.localtime(self.lease_tm)), self.hostname) -for vl in 20 30 40 50 60 90 -do - print_vlan $vl -done + +class hostlist(dict): + def __init__(self): + dict.__init__(self) + + def append(self, host): + if host.mac in self: + if host.state < self[host.mac].state: + self[host.mac] = host + else: + self[host.mac] = host + + def __str__(self): + rv = "" + for key in self: + rv += str(self[key]) + '\n' + return rv + + +hl = hostlist() + +# +# ip n +# +for line in subprocess.check_output(['ip', 'n']).decode('utf-8').split('\n'): + data = line.split(" ") + h = host() + h.ip = data[0] + try: + h.vlan = int(h.ip.split('.')[2]) + except IndexError: + pass + if len(data) == 6: + h. mac = data[4] + h.state = data[5] + else: + continue + hl.append(h) + +# +# leases +# +with open('/var/lib/misc/dnsmasq.leases', 'r') as fh: + for line in fh.read().split('\n'): + data = line.split(' ') + if len(data) == 5: + h = hl.get(data[1], host()) + h.lease_tm = int(data[0]) + h.mac = data[1] + h.ip = data[2] + try: + h.vlan = int(h.ip.split('.')[2]) + except IndexError: + pass + h.hostname = data[3] + if h.mac not in hl: + hl.append(h) + +for vlan in [20, 30, 40, 50, 60, 90]: + print("Hosts in VLAN %d" % vlan) + for host in hl.values(): + if host.vlan == vlan: + print(" *", host) + print() From 79dc87c707bc9b9bb253901ac8c8915dc638d36c Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Tue, 12 Sep 2023 08:11:36 +0200 Subject: [PATCH 3/4] dnsleases pimped - output sorted by hostname + ipx --- dnsleases | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dnsleases b/dnsleases index 41273e9..f4301a8 100755 --- a/dnsleases +++ b/dnsleases @@ -12,8 +12,13 @@ class host(object): self.hostname = '' 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): - 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): @@ -27,10 +32,19 @@ class hostlist(dict): else: 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): + entries = list(self.values()) + entries.sort(key=host.sortcriteria) rv = "" - for key in self: - rv += str(self[key]) + '\n' + for h in entries: + rv += str(h) + '\n' 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]: print("Hosts in VLAN %d" % vlan) - for host in hl.values(): - if host.vlan == vlan: - print(" *", host) + print(hl.vlan_list(vlan)) print() From bb3fb18730e1579db828f574d85e0d6ca18d8039 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Wed, 13 Sep 2023 21:41:06 +0200 Subject: [PATCH 4/4] raspi extend script added --- apt-extend-raspi | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 apt-extend-raspi diff --git a/apt-extend-raspi b/apt-extend-raspi new file mode 100755 index 0000000..c446b5b --- /dev/null +++ b/apt-extend-raspi @@ -0,0 +1,30 @@ +#!/bin/sh +# + +# +# Additional Packages +COMMON=" +zsh zsh-syntax-highlighting zsh-autosuggestions +vim vim-python-jedi vim-autopep8 git tmux +neofetch figlet powerline +" + +ALL=$COMMON + +echo The followin packages and their required depending packages will be installed: +echo ------------------------------------------------------------------------------ +echo $ALL +echo ------------------------------------------------------------------------------ +read -r -p "Are you sure? [y/N] " response +echo ------------------------------------------------------------------------------ +case "$response" in + [yY][eE][sS]|[yY]) + sudo apt-get -y install $ALL + # + echo + echo + ;; + *) + echo Installation aborted! + ;; +esac