[ALUG] What's a fast way to check for something on LAN?
cl at isbd.net
Wed Feb 22 17:05:26 GMT 2017
On Wed, Feb 22, 2017 at 04:58:05PM +0000, Mark Rogers wrote:
> 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 184.108.40.206
> 220.127.116.11 : xmt/rcv/%loss = 1/0/100%
> $ echo $?
> $ fping -c1 -t100 18.104.22.168
> 22.214.171.124 : , 84 bytes, 9.79 ms (9.79 avg, 0% loss)
> 126.96.36.199 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 9.79/9.79/9.79
> $ echo $?
> fping also does nice things like pinging multiple hosts if needed.
I'm already using the return value in ssh config, as I showed before:-
# Test if specified host is ping'able
! ping -c 1 $1 >>/dev/null 2>&1
The above (or the -w parameter for standard ping) is all I need to
quicken the response enough. A one second delay is probably fine so
I'll go with the -w1 with ping solution for the moment. If I get
really impatient I can use fping as above! :-)
More information about the main