Click here to Skip to main content
12,063,452 members (70,648 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C# QT-Creator
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++


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 4-Mar-13 19:48pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Read some of these links[^] for useful information.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160204.4 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100