Click here to Skip to main content
12,821,494 members (26,137 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 22 Feb 2006

ICMP the ping-tracert

, 22 Feb 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Make an ICMP request to make a ping or tracert.


I needed a ping server that is fully configurable (weight of package, update period, timeout etc.), and while lots of solutions exist, none of them are free. Moreover, I wanted a tracert for some other reason: I wanted to learn how it works.

This is not an impressive project; however, it can give a helping hand to people who want to implement in a single command, a ping or a tracert.

First look!

Console.WriteLine("**************TEST PING****************\r\n");
IcmpRequest myRequest = 
    new IcmpRequest(new ToolsCommandRequest(

Console.WriteLine("\r\n\r\n***********TEST TRACERT***********\r\n");
myRequest = new IcmpRequest(new ToolsCommandRequest("",
**********************TEST PING**********************

  Pinging [] with 32 bytes of data:
  Reply from bytes=32 time=94ms TTL 51
  Reply from bytes=32 time=78ms TTL 51
  Reply from bytes=32 time=78ms TTL 51
  Reply from bytes=32 time=78ms TTL 51

**********************TEST TRACERT*******************

  Tracing route to []
  over a maximum of 128 hops:
  1 1 ms []
  2 1 ms []
  3 1 ms []
  4 16 ms []
  5 16 ms []
  6 1 ms []
  7 78 ms []
  8 78 ms []
  9 109 ms []
  10 78 ms []
  11 94 ms []
  12 78 ms []
  13 94 ms []

  Trace complete.

In just two lines you have what you wanted.


You can find a lot of documentation on ICMP packet format, usage, etc., on the web. However, what you need to know is: All ICMP packets have 32 bits of header (8 bits for type, 8 bits for code and 16 bits for checksum). When you send an ICMP packet you have to define the TTL (time to live). It's the maximum number of hops that the request can make. If this number is too small to reach the host, an error occurs, and the ping won't be successful. Each time the packet transits to a host, the TTL is reduced by one unit.

By the way, you can define the TTL in Windows command prompt using the command: ping -i 5. You can also define it using this tool by creating the object ToolsCommandRequest. Here are its parameters:

//Default values

//Period in millisecond between 2 ping
public int periodUpdate = 1000;

//Type of request, can be ping or tracert                            
public CommandType myCommandType = CommandType.tracert;
//Host we want to reach
public string host = "";

//Weight of the packet in byte (should be minimum 1)
public int weightPacket = 32;

//Not used in this demo
public string sessionID;

//Number of times the request will be done on the host
public int nbrEcho = 4;

//Time out of the ping. If we don't have answer
//after that time, the ping triggers an error
public int timeout = 1000;

//TTL (see above for explanation)
public int timeToLiveMax = 128;

When you send an ICMP request, you must define the time to live in the IP level (not into the ICMP packet). But, when you receive the answer from the ICMP packet, the TTL is written into the ICMP packet (actually it's defined by the 8th byte).

Tracert or traceroute

The tracert uses the TTL property. The algorithm is as follows:

Send a ping with a TTL = 2, 
    the ping failed and return the host reached.
Send a ping with a TTL = 3, if the ping failed, 
    it return the host reached. If the ping succeed, 
    the tracert is completed
Send a ping with a TTL = 4, if the ping failed, 
    it return the host reached. If the ping succeed, 
    the tracert is completed


The mechanism of the ICMP DLL is quite simple. I took it from here and modified it to get the weight packet and the time to live properties. With that module you can easily configure a monitoring system based on ping.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Belgium Belgium

You'll be surprise about this incredible tool !

You may also be interested in...

Comments and Discussions

QuestionAdministrator Pin
dhenry_il13-Dec-12 5:01
memberdhenry_il13-Dec-12 5:01 
GeneralMy vote of 1 Pin
OmgShitNo14-Dec-09 4:06
memberOmgShitNo14-Dec-09 4:06 
GeneralRe: My vote of 1 Pin
wknopf29-Jan-11 16:40
memberwknopf29-Jan-11 16:40 
nasirkhanjadoon29-Feb-08 1:11
membernasirkhanjadoon29-Feb-08 1:11 
RichardMant13-Jul-08 2:41
memberRichardMant13-Jul-08 2:41 
GeneralICMP Ping Bug Pin
tankSanju17-Nov-06 2:22
membertankSanju17-Nov-06 2:22 
QuestionWhat about this? Pin
neil young28-Feb-06 1:26
memberneil young28-Feb-06 1:26 
AnswerRe: What about this? Pin
zitun28-Feb-06 7:09
memberzitun28-Feb-06 7:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 23 Feb 2006
Article Copyright 2006 by zitun
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid