Skip to content

Instantly share code, notes, and snippets.

@diegargon
Last active April 7, 2016 22:49
Show Gist options
  • Save diegargon/f37e5b56e58e8a36b3025a05099857b9 to your computer and use it in GitHub Desktop.
Save diegargon/f37e5b56e58e8a36b3025a05099857b9 to your computer and use it in GitHub Desktop.
Ping Scan multiple hosts 255.255.0.0 and output alive systems (threads)
#!/bin/bash
# diegargon http/mail:diego.envigo.net
#
# Ping Scan multiple hosts 255.255.0.0 and output alive systems
# Usage: ./ping-scan.bash 192.168
#
#Start config
ping_path="/usr/bin/fping"
ping_opt=" -t 200 "
ping="$ping_path $ping_opt"
threads="25"
#End config
counter="1"
a="$1"
if [ -z "$BASH_VERSION" ]; then
echo "This script requires the BASH"
exit 1
fi
if [ -z "$1" ]
then
echo "You need specify X.X ip, ex:192.168"
exit 1
fi
if [ ! -f "$ping_path" ];
then
echo "$ping_path not exist."
exit 1
fi
ping_func() {
trap "exit" int
for c in {1..254..1}
do
$ping $a.$b.$c 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
echo "$a.$b.$c"
fi
done
}
trap "exit" int
for b in {0..254..1}
do
if [ "$counter" -gt "$threads" ]
then
echo "Max threads reach ($threads)... waiting finish"
wait
counter=1
echo "Leaving waiting state"
fi
echo "Sending pings to $a.$b network"
ping_func &
counter=$((counter+1))
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment