Network related script

First of all,I would like to introduce about me,

This is my own try and this is not my homework,and I study myself reading shell script pdf guide from net and learn shell scripts bit by bit.I am self study learner.I try to work out shell scripts.please help to resolve this type of problem.when I am struggling

I am using Redhat Linux 4.4 operating system.
I want to ping 16 network ip address from server through shell script.I tried to develop the shell scripts for this reason. But I don't get the output.Please give the shell script for this program.let me know,
I am expecting output like this, for eg:

this is a server address : 192.168.1.2 

client address : 192.168.1.3 to 192.168.1.19 ( 16 ip address)

I want the output like this:-

  • how many ips are available and list that ips.
  • how many ips are not available and list that ips.

You could try something like this:

#!/bin/bash

upcnt=0
downcnt=0
for ip in 192.168.1.{3..19}
do
   if ping -c 1 -W 1 $ip > /dev/null
   then
        let upcnt=upcnt+1
        uplist="$uplist\n    $ip"
   else
        let downcnt=downcnt+1
        downlist="$downlist\n    $ip"
   fi
done

printf "$upcnt ips are available:$uplist\n"
printf "$downcnt ips are not available:$downlist\n"

Note: if not response from a server it will wait up to 1 second to be sure server is unreachable - so maximum runtime should be close to 17 seconds.

1 Like