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 esac
done 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 then
echo "Could not find arp-scan, which is required for pamela to scan the mac addresses" echo "Could not find arp-scan, which is required for pamela to scan the mac addresses"
fi fi
@ -68,11 +72,13 @@ fi
while true while true
do do
echo $(date)" scanning..." 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="" 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 do
[ -n "$MACS" ] && MACS="$MACS,$M" || MACS="$M"; [ -n "$MACS" ] && MACS="$MACS,$M" || MACS="$M";
let "NUM_MACS=NUM_MACS+1"
done done
POST="sn=$NETMASK&macs=$MACS" POST="sn=$NETMASK&macs=$MACS"
RESULT=$(wget "$OUT" -O - --quiet --post-data "$POST" || echo "wget error: $?") RESULT=$(wget "$OUT" -O - --quiet --post-data "$POST" || echo "wget error: $?")
@ -81,6 +87,7 @@ do
echo Error uploading results: echo Error uploading results:
echo "$RESULT" echo "$RESULT"
fi fi
echo $(date)" Uploaded $NUM_MACS mac addresses..."
echo $(date)" sleeping..." echo $(date)" sleeping..."
sleep "$SLEEP" sleep "$SLEEP"
done done