Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (41 sloc) 1002 Bytes
#!/bin/bash
#Author : Muneeb Shaikh
#E-mail : muneeb@reversehack.in
#Created: 20 Jan, 2011
clear
cnt=$(ping -c 4 google.com | grep "100% packet loss"| wc -l)
if [ $cnt = 0 ]; then
echo
echo "Your Computer is CONNECTED to the internet."
echo
else
echo
echo "Your Computer is NOT CONNECTED to the internet."
echo
fi
if [ $# -ne 2 ]
then
echo
echo Usage: alive FROM TO
echo
exit 1
fi
echo
echo "Script to check alive hosts on LAN by Muneeb Shaikh"
echo
CLASS=192.168.1.
FROM=$1
TO=$2
COUNT=2
for myHost in $(seq $FROM $TO)
do
count=$(ping -qc $COUNT ${CLASS}$myHost | grep 'received'| awk -F',' '{print $2}' | awk -F' ' '{print $1}')
echo "Testing Host ${CLASS}$myHost"
if [ $count -ne 0 ]; then
echo "Host: ${CLASS}$myHost is UP at $(date)"
notify-send -u normal "Alive Hosts" "Host: $myHost is UP at $(date)"
else
echo "Host: ${CLASS}$myHost is DOWN at $(date)"
fi
done
echo