Wednesday, January 11, 2012

Ping a list of servers

To do this, you need to put all the hosts that need to be checked in a file. For example, I put all my hosts in a file called ping_list:

$ cat ping_list
cat.myhost.net
dog.myhost.net
tiger.myhost.net
bird.myhost.net
There are a few ways to ping multiple hostnames, I'll list out what I have tried before:

1. Use nmap
$ nmap -sP -iL ping_list
Failed to resolve given hostname/IP: cat.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Failed to resolve given hostname/IP: dog.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Host 192.168.0.99 is up (0.00036s latency).
Host 192.168.0.100 is up (0.00061s latency).
where -sP is for ping test and -iL is for inputting from files.

2. One liner for loop
$ for i in `cat ping_list`; do ping -c1 $i; done
ping: unknown host cat.myhost.net
ping: unknown host dog.myhost.net
PING tiger.myhost.net (192.168.0.99) 56(84) bytes of data.

--- tiger.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

PING tiger.myhost.net (192.168.0.100) 56(84) bytes of data.

--- bird.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
I believe there are other tools or scripts beside those I listed above, but I always these 2 methods to ping multiple hosts. If you have other tools or script, please leave a comment.

Thanks