[ALUG] What's a fast way to check for something on LAN?

Mark Rogers mark at more-solutions.co.uk
Wed Feb 22 16:58:05 GMT 2017


On 22 February 2017 at 16:34, Simon Ransome <simon at 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.

-- 
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER



More information about the main mailing list