-2

I have a function that at the moment does a quick ping to a remote machine in the same network by doing so:

ping -n 1

It then evaluates the commands success (1 or 0) in order to determine whether the machine is powered on or not.

Seems that this approach is not working correctly as I will indeed get 1 from ping only if the DNS resolution for the IP am trying to ping fails. In any other case it seems that ping will return zero (even if the machine is indeed down) as it seems to loopback on itself.

Does anyone have a good idea for any suitable alternatives? I am considering telnet but this may take a long time to timeout and I want the best possible performance.

2 Answers2

0

First, it's not DNS resolution that is causing the first ping to fail, its ARP resolution.

Second, just increase the number of pings. This is what every single commercial and F/OSS monitoring system does.

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • Sorry for mistakenly stating that's DNS. I did mean ARP. In any way, I have thought of increasing the number of pings but by doing so I will get severe slowdown meaning that I will not be able to attain the required performance. So upping the number of pings is not a good idea, performance wise at least. – ArisKortex Dec 05 '16 at 14:48
  • 1
    ARP resolution is going to take the same amount of time regardless what protocol you use. If this is really so performance sensitive, then configure static ARP mappings for your devices. – EEAA Dec 05 '16 at 14:50
0

ICMP datagrams are 32 bits and you don't need to establish any connection (not like when using TCP, for example).
As already stated by some people, DNS has nothing to do with ping when directing it to an IP, it's ARP the one working/failing there.

You will have the best performance possible using a simple ping (I'd not ping just once) and having static ARP mappings (as stated by @EEAA) or filling up your server's ARP cache before checking anything so there's no delay (and possible failure) while your switch is asking who has the MAC Address for the IP being ping'd

sysfiend
  • 1,387
  • 1
  • 12
  • 24
  • Thanks for your reply. Having static ARP mappings in my case is not option so I might just go with a solution that will involve checking the ping's actual output and not just the execution result. – ArisKortex Dec 06 '16 at 09:39