0

This drives me crazy been searching and testing the whole day. I need a simple traceroute in c#. Ive been through all the major websites but i dont get how to list all the hops!

string hostName = "google.se";
Ping ping = new Ping();
var reply = ping.Send(hostName);

if (reply.Status == IPStatus.Success)
{
    Response.Write ("Address: " + reply.Address.ToString() + "<br>");
    Response.Write ("RoundTrip time: " + reply.RoundtripTime + "<br>");
    Response.Write ("Time to live: " + reply.Options.Ttl + "<br>");
    Response.Write ("Don't fragment: " + reply.Options.DontFragment + "<br>");
    Response.Write ("Buffer size: " + reply.Buffer.Length + "<br>");
}
else
{
    Response.Write (reply.Status);
}

.

EDIT: the q you posted as duplicate is the one ive been sitting with for the last five hours, and cant figure out

  • 1
    Possible duplicate of [TraceRoute and Ping in C#](http://stackoverflow.com/questions/142614/traceroute-and-ping-in-c-sharp) – Paul Abbott Nov 04 '16 at 21:22
  • Only some versions of Ping return the tracerout. I opened a cmd.exe and typed ping/? and the help results indicated the -k option in my ping will return the traceroute. – jdweng Nov 04 '16 at 21:23
  • http://stackoverflow.com/questions/142614/traceroute-and-ping-in-c-sharp – olk Nov 04 '16 at 21:30
  • An answer on the indicated duplicate question has the code for a traceroute implementation. You just need to copy and paste that into a C# file and compile, then you'd be able to do `Answer.TraceRoute.GetTraceRoute(hostName)`. What's the part you can't figure out? – Heretic Monkey Nov 04 '16 at 21:38
  • Ah thank you! I was so close. But how do i print the results? – Robin Lundquist Nov 04 '16 at 22:21
  • Ok i got it to print :D how do i gracefully add millisec and hostname? Btw ill give you a thumbsup if you make your Response as an answer! – Robin Lundquist Nov 04 '16 at 22:35

0 Answers0