How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Tracert implementation in C#

While I was looking for a tracert method that I could use for an application of mine I noticed that the .NET framework doesn’t provide one out of the box, so I decided to create one that matched my requirements.

The method below works in the exact same fashion the tracert method works. Providing
the method with the IP address, the max number of hops you would like to receive and a timeout value for the hops will allow you to track down the route your data will travel in order to get to their destination, as well as the time (in milliseconds) it will take for each hop.

Main method:

TracertEntry Class:

Usage:

Feel free to modify the code to suit your needs and as always post any feedback or questions you might have below in the comment section.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

6 Responses to Tracert implementation in C#

  1. Gregory M Owens says:

    Added hostname support by changing/adding the lines below

    if (!IPAddress.TryParse(host, out address) && Dns.GetHostAddresses(host).Length == 0)
    throw new ArgumentException(string.Format(“{0} is not a valid IP address or hostname”, host));

    if(address == null && Dns.GetHostAddresses(host).Length > 0)
    address = Dns.GetHostAddresses(host)[0];

  2. Arthur says:

    Anyplace where i can download the source code, without having to create a new project at vs?

    • CooLMinE says:

      Sorry we don’t have a demo project for this example.

      Nevertheless, it should be fairly easy to implement since you just require the TracertEntry class and the Tracert() method.

  3. hacker2000 says:

    Tip: If you want better performance comment out line 34-42 and line 49.
    So you don’t see the hostnames but it has a much better performance.

  4. rahul says:

    hey
    reply.Address and Dns.GetHostByAddress()
    both are deprecated by Microsoft so please suggest anything optional for them.

Leave a Reply

Your email address will not be published. Required fields are marked *