bugfixes to scannerscript: better check for root, no longer using sudo, outputting number of macs uploaded

This commit is contained in:
sandb 2009-12-30 15:47:11 +01:00
parent 6c45c61c2d
commit 0492a99232

View File

@ -58,9 +58,13 @@ do
esac
done
sudo -n true || { echo "Must be root to run pamela-scanner"; exit 1; }
if [ "$(id -ru)" != "0" ]
then
echo "Must be root to run pamela-scanner"
exit 1
fi
if [ -z "$(sudo which arp-scan)" ]
if [ -z "$(which arp-scan)" ]
then
echo "Could not find arp-scan, which is required for pamela to scan the mac addresses"
fi
@ -68,11 +72,13 @@ fi
while true
do
echo $(date)" scanning..."
NETMASK="$(ip -4 addr show "$IF" | egrep -o "brd [0-9\.]*" | egrep -o "[0-9\.]*")"
NETMASK="$(ip -4 addr show "$IF" | egrep -o "brd [0-9\.]+" | egrep -o "[0-9\.]+")"
MACS=""
for M in $(sudo arp-scan -R -i 10 --interface "$IF" --localnet | awk '{ print $2 }' | grep :.*: | sort | uniq)
NUM_MACS=0
for M in $(arp-scan -R -i 10 --interface "$IF" --localnet | awk '{ print $2 }' | grep :.*: | sort | uniq)
do
[ -n "$MACS" ] && MACS="$MACS,$M" || MACS="$M";
let "NUM_MACS=NUM_MACS+1"
done
POST="sn=$NETMASK&macs=$MACS"
RESULT=$(wget "$OUT" -O - --quiet --post-data "$POST" || echo "wget error: $?")
@ -81,6 +87,7 @@ do
echo Error uploading results:
echo "$RESULT"
fi
echo $(date)" Uploaded $NUM_MACS mac addresses..."
echo $(date)" sleeping..."
sleep "$SLEEP"
done