Trace Route Utility in ASP.Net C#

Category: ASP.NET

Trace Route Utility in ASP.Net C#

Introduction

Every connection to the internet has an IP address, or number, in simple terms you can say it is much like a phone number, which is unique. In this example we will use www.google.com as our site to trace route, and as you will see when you run this example that site will resolve to an IP address of 74.125.47.104.
As I mentioned earlier every connection has a unique number, BUT, remembering these numbers is difficult for most people, so these IP's also have Uniform Resource Locators, or URL's.
There are thousands of DNS or Domain Name Servers out there that look up these URLs (www.google.com is a URL) and translates them behind the scenes into the correct IP number, and you are then connected.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

What is a Trace route?

A trace route traces hop for hop, all the jumps you take from your internet connection to the destination. The first few hops are usually through your service provider's network. The hops from there are usually through the backbone/upstream provider your service provider uses to route internet traffic.
The last few hops will be with our upstream/backbone provider through our server network and to your server. Each hop shows timing information (designated by 3 sets of 'ms' ratings). Timing below 300 ms is good timing. Anything above that up to 1000 ms indicates some delays which will ultimately affect your overall connection performance. Any 'ms' timings represented by an asterisk (*) indicate a timeout (bad connection).
Whatever hops shows asterisks or timings above 500 will, more than likely, be where your connection is having problems.  If the problems occur, in the first few hops, it is your service provider. If the problems occur within the midway hops, it is your service provider's upstream/backbone connection.
If the problem occurs within the last few hops to your site, then it is a problem on the server end. Please note, if the problem occurs in the first few hops, it will affect most of the hops thereafter.

What we will learn in this article:

  • What is a Trace Route
  • How to create a Trace Route Utility for ASP.Net

Getting started with our example

The first thing we need to do to get started with our application is to create a new web application.

Start Visual Studio 2005 and create new Web Application project as illustrated in Fig. 1:


[Click to see full-size]


When you select the “OK” button the project will be created.

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

The next step in our example is to add the Trace Route code behind. For this example we are adding the code to the Page Load event of the application. When adding this to your application you might want to use another source for display rather than the web page itself, but for this example we are just trying to show you how easy it is to create your own Trace Route utility and we will utilize the web page for our output display.
Here is the code for the Page Load event:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
private System.Diagnostics.Process p;

protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Parse("6.7.1967 08:19:00"));

Page.Response.Clear();
Page.Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "filename=\"traceroute.txt\"");
Response.BufferOutput = false;
Page.Response.Output.Write("TraceRoute Information!\n\n");
Page.Response.Flush();

p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\\windows\\system32\\tracert";
p.StartInfo.Arguments = "www.google.com";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;

string strTemp = String.Empty;

while (strTemp != null && !p.HasExited)
{
strTemp = p.StandardOutput.ReadLine();
if (strTemp.Length > 3) Page.Response.Output.Write(strTemp + "\n");
Page.Response.Flush();
if (!Response.IsClientConnected)
{
p.Kill();
break;
}
}
Response.Flush();
Response.Close();
}
catch (Exception ex)
{
// Please Note:
// When you add this to your application you will want to change the
// exception handling to throw the correct exceptions rather than the
// generic Exception.
}
}
}

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Here is what our example will look like when it is run.

Fig. 2


[Click to see full-size]

What we have Learned

We have learned that we can easily write a utility that will allow us to Trace Route an IP address or a URL. If we use a URL we will see that the process will resolve that URL to its correct IP address.

Attachments



Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!

Leave a Comment

Comments on this Article

Post a Comment
Name:
Website:
Email:
Comments:

#1 sith kong

Posted By: sith kong | 9.09.2008 at 3:42 PM

I love it!

#2 Sumit Lathwal

Posted By: Sumit Lathwal | 10.01.2008 at 2:06 AM

Nice and informative article.

#3 Sandeepan Kundu

Posted By: Sandeepan Kundu | 7.09.2009 at 12:51 PM

I liked it much.... I have used processes but the concept of redirecting the standard output of process to stream and using the stream buffering is really amazing. never earlier thought in this way...

Thanks for such post..... 3 cheers for you...

#4 online games

Posted By: online games | 11.24.2009 at 11:01 PM

Nice and informative article.

#5 automatic litter boxes

Posted By: automatic litter boxes | 1.26.2010 at 5:14 PM

Nice and informative article.

#6 prescription swim goggles

Posted By: prescription swim goggles | 2.04.2010 at 2:43 AM

I have used processes but the concept of redirecting the standard output of process to stream and using the stream buffering is really amazing.

#7 SY0-201

Posted By: SY0-201 | 2.12.2010 at 12:40 AM

It would be nice if agnate to the way you can appearance Page.Trace contest in if you had this was congenital eyewitness but configurable to shut off if this is the assembly site.

#8 70-680

Posted By: 70-680 | 2.12.2010 at 12:41 AM

When I saw this at Mix I was acquisitive you guys would absolution it even admitting it's not harder to do myself. I just acquainted this is one of those things to DRY

#9 70-642

Posted By: 70-642 | 2.12.2010 at 12:43 AM

Nice one, Phil. As Cleve acicular out, it would be nice if this advice was printed out *after* the accustomed processing of a page. If I get about to accomplishing that, I'll forward a archetype aback to you.

#10 642-812

Posted By: 642-812 | 2.12.2010 at 12:44 AM

Just capital to say thanks. I was stuck; this unstuck me. You're the man, Phil. Thank you.

#11 PMI-001

Posted By: PMI-001 | 2.13.2010 at 7:23 AM

Thanks!

#12 online game

Posted By: online game | 3.07.2010 at 3:29 AM

Wonderful post...

#13 CISSP

Posted By: CISSP | 3.19.2010 at 4:34 AM

Great code, I hope, that it will help my in my project, but any way, you have done great work.

#14 wholesale shoes

Posted By: wholesale shoes | 5.24.2010 at 3:34 AM

Spring summer pocket perfect supporting role (figure) except heart shape brooch, earring, necklace,

#15 vibram five fingers

Posted By: vibram five fingers | 6.05.2010 at 9:25 AM

That great!Great article!useful That what i'm looking for!

#16 nike air max

Posted By: nike air max | 6.05.2010 at 9:28 AM

This article give me a great help!thank you very much!

#17 michael jordan shoes

Posted By: michael jordan shoes | 6.18.2010 at 8:59 PM

good post!!thank you

#18 tiffany co

Posted By: tiffany co | 7.21.2010 at 2:39 AM

many people choose Tiffany & Co brand.Now For classic and quality genuine silver jewelry, we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#19 tiffany jewelry

Posted By: tiffany jewelry | 7.21.2010 at 2:39 AM

many people choose Tiffany & Co brand.Now For classic and quality genuine silver jewelry, we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#20 tiffany jewellery

Posted By: tiffany jewellery | 7.21.2010 at 2:39 AM

many people choose Tiffany & Co brand.Now For classic and quality genuine silver jewelry, we present you the hottest Tiffany silver jewelry .get more http://www.tiffanyonsale.com/

#21 tiffany ring

Posted By: tiffany ring | 7.26.2010 at 6:54 AM

Tiffany On Sale Offer a wide range of fashionable Tiffany & Co silver jewelry, including Necklaces, Pendants, Bracelets, Earrings, Rings and Accessories with fantastic discount.more http://www.tiffanyonsale.com/

#22 tiffany bracelet

Posted By: tiffany bracelet | 7.26.2010 at 6:54 AM

Tiffany On Sale Offer a wide range of fashionable Tiffany & Co silver jewelry, including Necklaces, Pendants, Bracelets, Earrings, Rings and Accessories with fantastic discount.more http://www.tiffanyonsale.com/

#23 tiffany necklace

Posted By: tiffany necklace | 7.26.2010 at 6:54 AM

Tiffany On Sale Offer a wide range of fashionable Tiffany & Co silver jewelry, including Necklaces, Pendants, Bracelets, Earrings, Rings and Accessories with fantastic discount.more http://www.tiffanyonsale.com/

#24 nike shoes on sale

Posted By: nike shoes on sale | 8.02.2010 at 3:53 AM

www.cheapshoeshop.com/.../Air-Max-1-Leath

#25 mbt shoes

Posted By: mbt shoes | 8.10.2010 at 11:58 PM

you are welcome.

#26 accessorize

Posted By: accessorize | 8.20.2010 at 11:56 PM

You say well, I am agree with you very much. It is your best choice.

#27 accessorize

Posted By: accessorize | 8.20.2010 at 11:56 PM

You say well, I am agree with you very much. It is your best choice.

#28 air max shoes

Posted By: air max shoes | 8.25.2010 at 10:34 PM

Once we get there, so many wonderful dreams will come true and the pieces of our black nike air max shoes lives will fit together like a completed jigsaw puzzle. http://www.sellnikeairmax.com/

#29 Ugg

Posted By: Ugg | 8.26.2010 at 6:35 AM

Got any reason to say no to cheap UGG boots? UGG boots that prevailed for years will still warm your frozen toes with the featured sheepskin leather,get more http://www.uggbootuksale.com/

#30 <a href="http://www.jewelry-tiffany.com/replica-Jewelry-Tiffany-Couple-3-b0.html">tiffani & co</a>

Posted By: <a href="http://www.jewelry-tiffany.com/replica-Jewelry-Tiffany-Couple-3-b0.html">tiffani & co</a> | 8.27.2010 at 2:21 AM

good

#31 tiffany heart earrings

Posted By: tiffany heart earrings | 8.27.2010 at 2:22 AM

goods

#32 pandor jewelry

Posted By: pandor jewelry | 9.08.2010 at 8:56 PM

Thanks for sharing the information.