Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me to find qt c++ code to find the traceroute of an ip. Im a c# developer and new to qt i have developed below code but its in c# please help to translate it in qt c++


C#
public string Traceroute(string ipAddressOrHostName)
       {

           IPAddress ipAddress = Dns.GetHostEntry(ipAddressOrHostName).AddressList[0];

           StringBuilder traceResults = new StringBuilder();

           using (Ping pingSender = new Ping())
           {
               PingOptions pingOptions = new PingOptions();

               Stopwatch stopWatch = new Stopwatch();

               byte[] bytes = new byte[32];



               pingOptions.DontFragment = true;

               pingOptions.Ttl = 1;

               int maxHops = 30;


               traceResults.AppendLine(

                   string.Format(

                       "Tracing route to {0} over a maximum of {1} hops:",

                       ipAddress,

                       maxHops));



               traceResults.AppendLine();



               for (int i = 1; i < maxHops + 1; i++)
               {

                   stopWatch.Reset();

                   stopWatch.Start();

                   PingReply pingReply = pingSender.Send(ipAddress,5000,new byte[32], pingOptions);


                   stopWatch.Stop();

                   traceResults.AppendLine(

                       string.Format("{0}\t{1} ms\t{2}",

                       i,

                       stopWatch.ElapsedMilliseconds,

                       pingReply.Address));



                   if (pingReply.Status == IPStatus.Success)
                   {

                       traceResults.AppendLine();
                       traceResults.AppendLine("Trace complete."); break;

                   }


                   pingOptions.Ttl++;

               }


           }

           return traceResults.ToString();

       }
Posted

1 solution

Read some of these links[^] for useful information.
 
Share this answer
 
Comments
vishnulalr 5-Mar-13 6:40am    
can i use directly this code on qt
Richard MacCutchan 5-Mar-13 7:15am    
I don't know QT; however, it is C++ code, which is what you are asking for.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900