Shell script to ping a range of IPs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to ping a range of IPs
# 1  
Old 10-22-2009
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
# 2  
Old 10-22-2009
Code:
for i in `seq 1 50`
do
# set ping timeout to 2 sec
  ping 192.168.0.$i 2 |grep "no answer"
done

# 3  
Old 10-22-2009
This script is a bit more elaborate as it will perform the probes in parallel, so it doesn't take much time
Code:
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.

Last edited by Scrutinizer; 10-22-2009 at 11:01 PM..
# 4  
Old 10-23-2009
Thank you so much .Very helpful. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ping certain range of ip address

hey guys, In my program i am giving an initial ip & end ip. i just want to check every ip in that range is pingable or not echo "Enter the initial ip:" read inip echo "Enter the end ip:" read endip for (( i=0; i<=$endip; i++ )) do if ping -c 4 $inip then echo "pingable" else echo... (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies

2. Shell Programming and Scripting

Help with shell script - filter txt file full of ips

Hello again gentlemen. I would like to make a shell script to 'optimize' a plain text full of IPs. Let's suppose to have this text file: 1.192.63.253-1.192.63.253 1.0.234.46/32 1.1.128.0/17 1.116.0.0/14 1.177.1.157-1.177.1.157 1.23.22.19 1.192.61.0-1.192.61.99 8.6.6.6 I want to... (2 Replies)
Discussion started by: accolito
2 Replies

3. Shell Programming and Scripting

Help with shell script filtering IPs

Hello gentlemen. I would like to create a shell script (no perl or python please) to generate a list with those rules. Let's suppose I've this text file: a@A:soss(z)1.1.1.1 Opt!o:2.1.9.55 Azxk<ji>rC211.111.9.0-251.11.34.9 d=211.9.1.3 O.Oox 2.1.2.4-51.9.1.33... (6 Replies)
Discussion started by: accolito
6 Replies

4. Shell Programming and Scripting

Checking range of ips

Given a range of IPs similar to this: "212.63.183.19","212.63.183.19","3560945427","3560945427","CN","China" "217.7.143.0","217.7.143.0","3641151232","3641151232","CN","China" "218.0.0.0","218.31.255.255","3657433088","3659530239","CN","China"... (13 Replies)
Discussion started by: SkySmart
13 Replies

5. Shell Programming and Scripting

Ping shell script - need urgent help

Hi friends, i have a file contains IP address like below cat file.txt 10.223.20.1 10.223.20.2 10.223.20.3 10.223.20.4 10.223.10.5 . . . like this Now i want to make a script which gives output whether each ip is pinging or not... the result will be like this 10.223.20.1 up... (9 Replies)
Discussion started by: siva kumar
9 Replies

6. Shell Programming and Scripting

Perl : ping for multiple IPs not working

I have written perl ping program to ping list of IPs one by one and print the status.But each and every time it is showing the status as Pass for all IPs even though the IP is wrong. multipleip.pl use Net::Ping; $p = Net::Ping->new(); $ifile="inventory.txt"; ... (2 Replies)
Discussion started by: scriptscript
2 Replies

7. Shell Programming and Scripting

Shell Script for ping, Linux

I woul like to create a script in order to make a ping to a server and save in a variable a 1 if respond or a 0 if it doesnt. Then with that I could make a graffic of the server, for how long it is up.:b: So far I have this: if ; then #if the ip respond the ping shows online echo... (3 Replies)
Discussion started by: jsebastiang0
3 Replies

8. Shell Programming and Scripting

shell script for ping

hi anyone, i want shell script for ping command. any one post here............ (10 Replies)
Discussion started by: rameshreddy.ema
10 Replies

9. Shell Programming and Scripting

perl return ips after successful ping

Hi, I have this script in ksh, what it does is loop every ip in the nodes_nso and produced another variable up_nodes_nso of only ip's that are up. nodes_nso=$(cat /var/tmp/nodes.txt) echo "ICMP Tests:" up_nodes_nso="" for ip in ${nodes_nso} ; do ping ${ip} 3 > /dev/null if ; then ... (1 Reply)
Discussion started by: borderblaster
1 Replies

10. Red Hat

Which IPs from the range are assigned to DHCP enabled clients

Hi All dhcpd.conf has a range of IPs sa for example( 192.168.1.201 192.168.1.220) So this is the range of IP addresses the server will issue to DHCP enabled PC clients booting up on the network How do i know which IPs are being used or which IPs from the range are assigned to dhcp enabled... (11 Replies)
Discussion started by: tannu
11 Replies
Login or Register to Ask a Question