Sponsored Content
Top Forums Shell Programming and Scripting Shell script to ping a range of IPs Post 302364356 by Scrutinizer on Thursday 22nd of October 2009 09:49:26 PM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
GREPCIDR(1)						      General Commands Manual						       GREPCIDR(1)

NAME
grepcidr -- Filter IP addresses matching IPv4 CIDR/network specification SYNOPSIS
grepcidr [-V] [-c] [-v] [-e pattern | -f file] DESCRIPTION
This manual page documents briefly the grepcidr command. This manual page was written for the Debian distribution because the original program does not have a manual page. grepcidr can be used to filter a list of IP addresses against one or more Classless Inter-Domain Routing (CIDR) specifications, or arbi- trary networks specified by an address range. As with grep, there are options to invert matching and load patterns from a file. grepcidr is capable of comparing thousands or even millions of IPs to networks with little memory usage and in reasonable computation time. OPTIONS
-V Show software version -c Display count of the matching lines, instead of showing the lines -v Invert the sense of matching, to select non-matching IP addresses -e Specify pattern(s) on command-line -f Obtain CIDR and range pattern(s) from file EXAMPLES
grepcidr -f ournetworks blocklist > abuse.log Find our customers that show up in blocklists grepcidr 127.0.0.0/8 iplog Searches for any localnet IP addresses inside the iplog file grepcidr "192.168.0.1-192.168.10.13" iplog Searches for IPs matching indicated range in the iplog file script | grepcidr -vf whitelist > blacklist Create a blacklist, with whitelisted networks removed (inverse) grepcidr -f list1 list2 Cross-reference two lists, outputs IPs common to both lists AUTHOR
This manual page was written by Ryan Finnie ryan@finnie.org for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. GREPCIDR(1)
All times are GMT -4. The time now is 02:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy