Skip to content

Instantly share code, notes, and snippets.

@TaIos
Created August 28, 2018 13:21
Show Gist options
  • Save TaIos/cdfbfd404d0ce89fa072e9185e4a3a87 to your computer and use it in GitHub Desktop.
Save TaIos/cdfbfd404d0ce89fa072e9185e4a3a87 to your computer and use it in GitHub Desktop.
Simple bash ping-sweeper
#!/bin/bash
# Simple ping-sweeper scan to determine which
# devices on a subnet respond to ping.
# Non-responding to ping does not mean
# that device is not up !
TIMESTAMP="$(date +%Y-%m-%d.%H:%M:%S)"
OUT="scan_${TIMESTAMP}.txt"
RED="\033[0;31m"
WHITE="\033[0;37m"
trap 'echo; exit 2' INT
read -p 'Please enter subnet: ' SUBNET
echo "Writing to file: '${OUT}'"
for IP in $(seq 1 254)
do
printf "%-15s ==> " "${SUBNET}.${IP}" | tee -a "${OUT}"
ping -c 1 "${SUBNET}.${IP}" > /dev/null 2>&1
if [ $? -eq 0 ]
then
printf "${RED}up${WHITE}\n" | tee -a "${OUT}"
else
printf "down\n" | tee -a "${OUT}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment