Created
March 6, 2026 16:00
-
-
Save eqhmcow/a85ac4197997be2876ef1f414e77676c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # this pulls mac addresses and IPv4 addresses from DHCP allocations that dnsmasq made | |
| #set -x | |
| cd /var/log | |
| zcat syslog.4.gz syslog.3.gz syslog.2.gz | | |
| cat - syslog.1 syslog | | |
| grep -a dnsmasq-dhcp | | |
| grep -a DHCPACK | | |
| grep -a -v 'UFW BLOCK' | | |
| perl -p -e 's/^.*192\.168\.0\.\d+ (\S+).*$/$1/' | | |
| sort -u | | |
| while read i | |
| do echo $i | |
| j=`zcat syslog.4.gz syslog.3.gz syslog.2.gz | | |
| cat - syslog.1 syslog | | |
| grep -a -e "$i" | | |
| tail -n1` | |
| echo $i $j | |
| done | | |
| grep -a wingfly | | |
| sort | | |
| perl -p -e 'undef $_, next unless s/wingfly dnsmasq-dhcp\[\d+\]: DHCPACK\([^)]+\) (\S+) \S+/$1/; undef $b; if (s/(192\.168\.0\.\d+)$//) { $b=$1; chomp; $_ .= `avahi-resolve-address $b 2> /dev/null` ; chomp; | |
| unless (m/$b/) { s/$/$b/ } $_.="\n" }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # update hosts file with current IPv6 addresses that hosts on my network are using | |
| # run e.g. as: | |
| #cat original-hosts > /etc/hosts ; while [[ 1 ]] ; do ./update-etc-hosts ; cat /etc/hosts ; head /etc/hosts ; sleep 60 ; done | |
| #set -x | |
| ./show-hosts | tee show-hosts.output | |
| # handle v6 | |
| conntrack -f ipv6 -L 2>/dev/null | perl -p -e 'while(s/^(.*?)(src|dst)=(\S+)/$2 $3 $1/) {}; s/^(.*(dst|src) \S+).*$/$1 /; s/(dst|src) //g; $_=join "\n", split; $_.="\n"' | sort -u | while read i ; do echo -n "$i " ; ip neigh show $i | grep lladdr | perl -p -e 's/^.*lladdr (\S+).*/$1 - good mac/; chomp;' ; echo ; done | grep 'good mac' | perl -p -e 's/ - good mac//' | while read i j ; do echo -n "$i " ; grep $j show-hosts.output ; done | perl -p -e 's/^(\S+) .*\s+(.+)$/$1 $2/' | grep -v '192\.168\.0' | while read i j ; do if grep -P "$i\\s" /etc/hosts ; then perl -p -i -e "s/$i\\s.*\$/$i $j/" /etc/hosts ; else echo $i $j >> /etc/hosts ; fi ; done | |
| # handle avahi | |
| cat show-hosts.output |grep -P '\.local$' | perl -p -e 's/^.*(192\S+).*$/$1/' | while read i ; do avahi-resolve-address $i ; done | perl -p -e 's/^(\S+)\s+/$1 /' | while read i j ; do if grep -P "$i\\s" /etc/hosts ; then perl -p -i -e "s/$i\\s.*\$/$i $j/" /etc/hosts ; else echo $i $j >> /etc/hosts ; fi ; done | |
| # handle v4 | |
| for i in `seq 0 255` ; do grep -Pe "192\\.168\\.0\\.$i\s+" show-hosts.output ; done | perl -p -e 's/^.*(192\.168\.0\.\d+).*$/$1/' | sort -u | while read i ; do echo -n "$i " ; dig +short -x $i | perl -p -e 's/\.$//' ; echo ; done | perl -p -e 'undef $_ unless m/^192\.168\.0\.\d+\s+\S/' | while read i j ; do if grep -P "$i\\s" /etc/hosts ; then perl -p -i -e "s/$i\\s.*\$/$i $j/" /etc/hosts ; else echo $i $j >> /etc/hosts ; fi ; done | |
| # handle tailscale | |
| tailscale status | grep -Pv '^\s*#|^\s*$' | perl -p -e 's/^(\S+)\s+(\S+).*$/$1 $2/' | while read i j ; do if grep -P "$i\\s" /etc/hosts ; then perl -p -i -e "s/$i\\s.*\$/$i $j/" /etc/hosts ; else echo $i $j >> /etc/hosts ; fi ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment