On 22 February 2017 at 16:34, Simon Ransome simon@nosher.net wrote:
This does it in exactly one second, if that's any use:
ping -c1 n.n.n.n -w1
(just look for "100% packet loss" in the output).
ping also returns 0 on success and 1 on failure so checking $? is simpler than grepping the output.
You can get a sub-second test using fping: $ sudo apt-get install fping $ fping -c1 -t100 123.123.123.123
123.123.123.123 : xmt/rcv/%loss = 1/0/100% $ echo $? 1 $ fping -c1 -t100 8.8.8.8 8.8.8.8 : [0], 84 bytes, 9.79 ms (9.79 avg, 0% loss)
8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 9.79/9.79/9.79 $ echo $? 0
fping also does nice things like pinging multiple hosts if needed.