Skip to content

Instantly share code, notes, and snippets.

@xlphs
Created February 2, 2015 05:59
Show Gist options
  • Save xlphs/d22de21bc92774c1180f to your computer and use it in GitHub Desktop.
Save xlphs/d22de21bc92774c1180f to your computer and use it in GitHub Desktop.
#!/bin/sh
trap "exit 0" INT
if [ $# = 0 ]; then
echo
echo "Usage: $0 <interface> [start ip addr] [end ip addr]"
echo " Sorry, it's not more configurable than that, edit the source."
echo
exit 1
fi
INTERFACE="$1"
oct1a="192"
oct1b="192"
oct2a="168"
oct2b="168"
oct3a="0"
oct3b="0"
oct4a="0"
oct4b="255"
if [ "$2" != "" ]; then
oct1a=$(echo $2 | tr "." " " | awk '{ print $1 }')
oct2a=$(echo $2 | tr "." " " | awk '{ print $2 }')
oct3a=$(echo $2 | tr "." " " | awk '{ print $3 }')
oct4a=$(echo $2 | tr "." " " | awk '{ print $4 }')
fi
if [ "$3" != "" ]; then
oct1b=$(echo $3 | tr "." " " | awk '{ print $1 }')
oct2b=$(echo $3 | tr "." " " | awk '{ print $2 }')
oct3b=$(echo $3 | tr "." " " | awk '{ print $3 }')
oct4b=$(echo $3 | tr "." " " | awk '{ print $4 }')
fi
echo "Scanning $oct1a.$oct2a.$oct3a.$oct4a - $oct1b.$oct2b.$oct3b.$oct4b on interface $INTERFACE"
# seq doesnt exist on some retarded boxen, comment out if your box is too
# stupid to have bc and/or tr
seq() { echo "for (i=$1; i<=$2; i++) i;" | bc | tr "\012" " "; }
# Check arping exit status depending on the one you have installed.
# Assuming arping from iputils package.
for a in $(seq $oct1a $oct1b); do
for b in $(seq $oct2a $oct2b); do
for c in $(seq $oct3a $oct3b); do
for d in $(seq $oct4a $oct4b); do
sh -c "arping -qD -c 1 -I $INTERFACE $a.$b.$c.$d
if [ \$? = 1 ]; then
echo Got answer with address: $a.$b.$c.$d
fi" &
done
wait
done
done
done
#exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment