Shell script to ping a range of IPs

Hi

Can someone give me a shell script that can ping a range of IPs and return IPs which are not pingable.

Range for example say 192.168.0.1 to 192.168.0.50 and whichever are not pingable then return the IP.

Thanks for your help

for i in `seq 1 50`
do
# set ping timeout to 2 sec
  ping 192.168.0.$i 2 |grep "no answer"
done

This script is a bit more elaborate as it will perform the probes in parallel, so it doesn't take much time

probe () {
  ping -c1 -w5 $1 >&- 2>&- || touch /tmp/pingfail.$1
}
rm /tmp/pingfail.* 2>&-
for i in $(seq 1 50); do
  probe 192.168.0.$i &
done;
wait
for failip in /tmp/pingfail.*; do
  echo ${failip#*.}
done|sort -nt. -k1,1 -k2,2 -k3,3 -k4,4
rm /tmp/pingfail.* 2>&-

You'd have to check if the ping on your system supports these options or use something equivalent, so that the ping stops after a number of seconds:

My man ping:

   -c count
          Stop  after  sending  count ECHO_REQUEST packets. With deadline option, ping waits for count
          ECHO_REPLY packets, until the timeout expires.

   -w deadline
          Specify  a  timeout,  in seconds, before ping exits regardless of how many packets have been
          sent or received. In this case ping does not stop after count  packet  are  sent,  it  waits
          either for deadline expire or until count probes are answered or for some error notification
          from network.

Thank you so much .Very helpful. Thanks