Friday, November 28, 2008

Ping Every Host in /etc/hosts File.

If you want to know whether hosts specified in /etc/hosts file are reachable, just give the following command:

$ awk '/^[0-9]/{print $1}' /etc/hosts | xargs -l ping -c 1 $1

Sample run:

$ awk '/^[0-9]/{print $1}' /etc/hosts | xargs -l ping -c 1 $1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.046 ms

--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.046/0.046/0.046/0.000 ms
PING 127.0.1.1 (127.0.1.1) 56(84) bytes of data.
64 bytes from 127.0.1.1: icmp_seq=1 ttl=64 time=0.028 ms

--- 127.0.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.028/0.028/0.028/0.000 ms


No comments: