ICMP Ping Library

As part of a project I’m working on, I need to ping computers on my network with the Arduino Ethernet shield. I saw several old posts on the forum asking how to send out pings from the ethernet shield, so I’ve made my ping code into a library, available here:


I hope someone finds this useful!

Ooooh, nice. Many thanks! Even if I don't use it I'm sure I will be able to learn a lot from it.

Many thanks for your efforts.


Is it possible to get the packet loss value with your library?

Thank for the code, I will have a look at it

Oh... by the way, nice web site ;)

I tried to use this tiny little library in my arduino project because i lost connection between the ethernet shield and my router. After reconnection i always had to reset the arduino to make ethernet working again. So my idea was to use the ICMPPing every hour to find out if my connection still exists. If not i do a "ethernet.begin(..)" again and with this the w5100 is not resetted but restarted and in most cases the net is working again.

But i have the weird behavior that every second hour the ping gets a timeout even when the net is ok.

Here is a small part of my logfile (because i couldn't believe it i extended the text which is given back so that i can see how many loops have been passed in every case):

Dienstag 2010-11-30 19:05:04
Request Timed Out. Reply[4]
Dienstag 2010-11-30 20:05:06
Reply[1] from: bytes=32 time=2ms TTL=128
Dienstag 2010-11-30 21:05:07
Request Timed Out. Reply[4]
Dienstag 2010-11-30 22:05:05
Reply[1] from: bytes=32 time=2ms TTL=128

I changed the used socket number from 0 to 1 with no effect.

Concerning the net my application is reacting passive. That means that in the BIG loop nothing happens if there is no request from another computer. If there is a request it is executed and then the loop starts again. So when i am calling the ping there is no other net activity pending on the arduino.

Anybody who has an idea?

Thanks a lot. Klaus

It seems that i found a solution for my problem:

Using socket number 3 all pings are successful. I expanded the ping-example with the WebServer example (from the Ethernet library) and with socket #0 and 1 i had no success. Then i tried socket number 3 in my own application and since then everything is fine.

Thanks to Blake for this routine. I tried to examine the source but it is really tricky and goes very deep so i didn't try to make any changes.


Thanks, this is very useful. Found this by accident looking for the Parallax PING...