7

Often, in applications that I develop, I like to include a network status indicator for various devices on the network. The easiest way to monitor these devices is by pinging them. But ICMP echoes are often difficult to integrate into an application due to security requirements with raw sockets, or performance issues with shelling out to ping. Also, for situations where this isn't a problem, I'm kind of over writing slightly different variations of the same ping code for various situations.

Most of the devices that I monitor are embedded devices with minimal network capabilities (but always include ICMP echo), so I do have to stick with this protocol, things like Echo Protocol (pointed out by Mark in comments below, thanks!) usually aren't available to me.

Is there a service that already exists that can provide low-overhead ICMP ping services to a non-root application?

I am considering writing a service that runs as root and allows other non-root applications to connect to it, add devices to monitor, and then query ping times and network status from it, but I don't want to reinvent a wheel and I'm wondering if something like this exists already.

3
  • 2
    Does en.wikipedia.org/wiki/Echo_Protocol look like something you could use? It's not ICMP. It's usually pretty easy to install the server. – Mark Plotnick Oct 10 '14 at 16:26
  • @MarkPlotnick That is a good suggestion when available, and easy to integrate into a client. Unfortunately, most of the devices that I am monitoring are usually custom or minimal embedded systems that support ICMP echo but not Echo Protocol. – Jason C Oct 10 '14 at 16:28
  • 2
    I think the most common strategy used by non-root programs is to run the ping command itself. It has options to make it silent, and then you can just check the termination status to see if it was successful or not. – Barmar Oct 10 '14 at 16:46
2

The answer to your question is probably "No, there is not."

The reason for this is that ICMP is a low level protocol, and in order to produce ICMP traffic, an application needs privileged access to your network interface. You can see evidence this on most systems by the fact that the binaries that generate ICMP are set-uid root. Note the sticky bit:

$ ls -l /sbin/ping /usr/sbin/traceroute
-r-sr-xr-x  1 root  wheel  28088 Aug 12 12:19 /sbin/ping
-r-sr-xr-x  1 root  wheel  28608 Aug 12 12:20 /usr/sbin/traceroute

(This is on FreeBSD. Your results on other operating systems may be different.)

For an application to generate raw network traffic, it needs to run as root. Since /sbin/ping already runs as root, your best bet is likely to use it to generate your pings.

If you're doing this for a large number of hosts, you might want to look at fping. Another option would be tcping, which can generate TCP packets that provide similar results to an ICMP ping. The requirement would be an open port on the target system to receive the packet. You might be able to use this or replicate its approach based on the source. Both of these may already be available as a package for your operating system.

For a larger scale monitoring solution, Nagios and Zabbix are popular free options, but there are many others.

1

Maybe too bloated for what you are looking for, but most full-fledged monitoring solutions such as Nagios, icinga or check_mk provide icmp monitoring and often provide APIs that you can query.

1
  • Hey that's not a bad idea; I forgot about nagios and I've never tried the others. I'll spend some time with them and see if I can find one that's easy to integrate. – Jason C Oct 27 '14 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.