From 0492a9923253031cfa728c1fbb7a204b5206c057 Mon Sep 17 00:00:00 2001 From: sandb Date: Wed, 30 Dec 2009 15:47:11 +0100 Subject: [PATCH] bugfixes to scannerscript: better check for root, no longer using sudo, outputting number of macs uploaded --- pamela-scanner.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pamela-scanner.sh b/pamela-scanner.sh index 01690d2..b48f5ff 100755 --- a/pamela-scanner.sh +++ b/pamela-scanner.sh @@ -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