Faster way than ping for checking if computer online?
Solution 1
Sending a single packet and waiting for a response is going to be one of the fastest possible ways, and ping is a fine way to do that. In fact, depending on your use case, I'd argue that it's too fast, since it doesn't really tell you if the system is actually doing anything useful, just that the kernel's network subsystem is alive and configured.
But assuming that's good enough, you can make some improvements. First, you could use -W1
to decrease the ping timeout to one second. Second, you could make your script ping the different hosts asynchronously (in a background thread), and check the results as needed rather than waiting.
Alternately, you can re-think the approach and have the remote systems check in somehow when they're up, and if a system hasn't checked in, you can assume it's down.
Solution 2
This is what fping was designed for. http://fping.sourceforge.net/
You need to parse the output afterwards instead of relying on a return code, but it is much faster than doing normal ping.
Solution 3
This would only work for one or two computers, but if you connect them directly to the computer responsible for checking their status, you can use ethtool
to see if the link is active or not.
Solution 4
What you could do it ping the broadcast address which should cause all the computers to ping back. Then you could cross check this list against what you have in SQLite to ensure all the computers are up.
Other then that a ping is probably the fastest way to ensure a computer is awake on a network. As mentioned by the other answer this doesn't provide any really useful data. If you have the ability to install scripts you can add a cronjob to ping a central server, run a task, or just echo out the process list to a central server which will log the request. Then simply checking that will tell you if you have any issues with no need to manually check every time.
Solution 5
Ganglia uses multicast traffic to monitor many hosts in a cluster, perhaps you could use something similar? This assumes that your networking hardware allows multicast traffic between all the hosts and your monitoring system.
Related videos on Youtube
Jon Phenow
Updated on September 17, 2022Comments
-
Jon Phenow over 1 year
I'm writing a wake on lan script for a set of our lab computers. We have sqlite db with a list of the computer hostnames, IPs, and MACs and currently I ping each of them with '-c1' so it doesn't run endlessly - but even that takes some waiting, is there a quicker way to get answer rather than ping? Using ping seems to slow the script quite a bit as it needs the ping answers to continue.
Thanks much for any suggestions!
-
mattdm about 13 yearsI assume you mean ping the broadcast address, not the gateway. On modern systems, that probably won't work. See unix.stackexchange.com/questions/7458/cant-ping-broadcast
-
richardtallent about 13 years@mattdm: Multicast then? I wasn't aware most people turned it off. I haven't had encountered issues with it before.
-
Jon Phenow about 13 yearsHaha yes thanks mattdm, a similar problem you can see I ran into. its not that people turn them off but they generally come with broadcast off lately apparently.
-
Jon Phenow about 13 yearsGood call on the -w addition, had to make it two though cause a bunch of computers didn't respond quick enough. Might look into adding some sort of periodic check-in as well or hand-shake but for now want to have the process relatively external to the computers I'm turning on.
-
Jon Phenow about 13 yearsLooks like a cool tool but for the purposes of this little script might add some unnecessary chunk to the project, keepin' it as a pretty small script for now. Will definitely keep my eye on it though, looks like a tool I might use soon non-the-less.
-
Shawn J. Goff about 13 yearsI also use -s to send a smaller packet.
-
mattdm about 13 yearsI'll be shocked if sending a smaller packet makes a difference.
-
mazianni about 13 yearsCould use fping (fping.sourceforge.net) to ping a list of hosts in parallel. Then you don't have to rely on being able to ping the broadcast address.
-
Jon Phenow about 13 yearsAren't they pretty much already sent at near minimum size of packets?
-
mattdm about 13 yearsThey're pretty small; there's a default of 56 data bytes, which you could reduce. But in any case, it's smaller than the ethernet MTU and bigger than nothing, so it comes down to "one packet" either way.
-
Johan about 13 yearsI have not used ethtool for this, would you like to give a example? (or maybe a link)?
-
LawrenceC about 13 years
ethtool {network_interface} | grep "Link detected" | cut -f 3 -d ' '
will returnyes
if a machine is connected, andno
if it is not. -
Thorbjørn Ravn Andersen over 6 yearsNote that ping comes in different flavors. You most likely want the one that goes all the way to the network stack.
-
Amol about 6 yearsI think it's kinda funny the description says "Unlike ping, fping is meant to be used in scripts and its output is easy to parse." and yet it doesn't provide a return code
-
Thorbjørn Ravn Andersen about 6 yearsWhat would good values be for the return code?