2009-12-28 19:16:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
<<LICENSE
|
|
|
|
|
|
|
|
Copyright 2009 Pieter Iserbyt
|
|
|
|
|
|
|
|
This file is part of Pamela.
|
|
|
|
|
|
|
|
Pamela is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Pamela is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
2009-12-29 21:53:31 +00:00
|
|
|
function usage {
|
|
|
|
|
|
|
|
echo 'Usage: pamela-scanner [OPTIONS]
|
|
|
|
|
|
|
|
-i INTERFACE Interface to arp-scan
|
|
|
|
-o URL The url of the pamela upload script (including /upload.php)
|
|
|
|
-s TIME The time to sleep between scans in seconds.
|
|
|
|
-h Shows help
|
|
|
|
|
|
|
|
Pamela is an arp-scanner, it uploads the mac addresses in your local lan on a webserver
|
|
|
|
where you get a visual representation of the mac addresses present. Multiple people
|
|
|
|
on multiple lans can run pamela together against the same server, where all results
|
|
|
|
are agregated. In short, pamela gives you an overview of how big the shared network is.'
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IF='wlan0'
|
2010-02-04 22:27:10 +00:00
|
|
|
OUT='http://hackerspace.be/pam/upload.php'
|
2009-12-30 11:23:38 +00:00
|
|
|
SLEEP='120'
|
2009-12-28 19:16:04 +00:00
|
|
|
|
2009-12-29 21:53:31 +00:00
|
|
|
TEMP=$(getopt -o 'hi:o:s:-n' "pamela arp scanner" -- "$@")
|
2009-12-28 19:16:04 +00:00
|
|
|
if [ $? != 0 ] ; then echo "Could not parse parameters..." >&2 ; exit 1 ; fi
|
2009-12-29 21:53:31 +00:00
|
|
|
eval set "$TEMP"
|
2009-12-28 19:16:04 +00:00
|
|
|
while true
|
|
|
|
do
|
2009-12-29 21:53:31 +00:00
|
|
|
shift;
|
|
|
|
[ -z "$1" ] && break;
|
2009-12-28 19:16:04 +00:00
|
|
|
case "$1" in
|
|
|
|
-i) IF="$2"; shift;;
|
|
|
|
-o) OUT="$2"; shift;;
|
|
|
|
-s) SLEEP="$2"; shift;;
|
2009-12-29 21:53:31 +00:00
|
|
|
-h|'-?') usage; break;;
|
|
|
|
*) echo "Unknown param: [$1]"; usage; exit 1;
|
2009-12-28 19:16:04 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-12-30 14:47:11 +00:00
|
|
|
if [ "$(id -ru)" != "0" ]
|
|
|
|
then
|
|
|
|
echo "Must be root to run pamela-scanner"
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-12-29 21:53:31 +00:00
|
|
|
|
2009-12-30 14:47:11 +00:00
|
|
|
if [ -z "$(which arp-scan)" ]
|
2009-12-29 21:53:31 +00:00
|
|
|
then
|
|
|
|
echo "Could not find arp-scan, which is required for pamela to scan the mac addresses"
|
|
|
|
fi
|
|
|
|
|
2009-12-28 19:16:04 +00:00
|
|
|
while true
|
|
|
|
do
|
|
|
|
echo $(date)" scanning..."
|
2009-12-30 14:47:11 +00:00
|
|
|
NETMASK="$(ip -4 addr show "$IF" | egrep -o "brd [0-9\.]+" | egrep -o "[0-9\.]+")"
|
2009-12-29 21:53:31 +00:00
|
|
|
MACS=""
|
2009-12-30 14:47:11 +00:00
|
|
|
NUM_MACS=0
|
|
|
|
for M in $(arp-scan -R -i 10 --interface "$IF" --localnet | awk '{ print $2 }' | grep :.*: | sort | uniq)
|
2009-12-29 21:53:31 +00:00
|
|
|
do
|
|
|
|
[ -n "$MACS" ] && MACS="$MACS,$M" || MACS="$M";
|
2009-12-30 14:47:11 +00:00
|
|
|
let "NUM_MACS=NUM_MACS+1"
|
2009-12-29 21:53:31 +00:00
|
|
|
done
|
|
|
|
POST="sn=$NETMASK&macs=$MACS"
|
|
|
|
RESULT=$(wget "$OUT" -O - --quiet --post-data "$POST" || echo "wget error: $?")
|
|
|
|
if [ -n "$RESULT" ]
|
|
|
|
then
|
|
|
|
echo Error uploading results:
|
|
|
|
echo "$RESULT"
|
|
|
|
fi
|
2009-12-30 14:47:11 +00:00
|
|
|
echo $(date)" Uploaded $NUM_MACS mac addresses..."
|
2009-12-28 19:16:04 +00:00
|
|
|
echo $(date)" sleeping..."
|
|
|
|
sleep "$SLEEP"
|
|
|
|
done
|