iopsys-feed/netmode/files/sbin/netmode-discover
2018-09-13 15:13:59 +02:00

47 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
mask_to_cidr() {
nbits=0
IFS=.
for dec in $1 ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7;;
252) let nbits+=6;;
248) let nbits+=5;;
240) let nbits+=4;;
224) let nbits+=3;;
192) let nbits+=2;;
128) let nbits+=1;;
0);;
*) echo "Error: $dec is not recognised"; exit 1
esac
done
echo "$nbits"
}
while true; do
[ -e /sys/class/net/br-wan ] || {
sleep 5
continue
}
unlisted=0
ps | grep wifi | grep -q reload || {
for mac in $(brctl showmacs br-wan 2>/dev/null | tail -n +2 | grep no | awk '{print$2}'); do
grep -q "$mac" /proc/net/arp || unlisted=$((unlisted+1))
done
ipaddr=$(ifconfig br-wan | grep -v inet6 | grep inet | tr ':' ' ' | awk '{print$3}')
netmask=$(ifconfig br-wan | grep -v inet6 | grep inet | tr ':' ' ' | awk '{print$7}')
mask=$(mask_to_cidr $netmask)
}
if [ $unlisted -gt 0 -a -n "$ipaddr" -a -n "$netmask" -a $mask -ge 24 ]; then
fping -c 1 -t 1000 -g $ipaddr/$mask -q >/dev/null 2>&1
fi
sleep 30
done