Click here to Skip to main content
11,704,315 members (54,148 online)
Rate this: bad
good
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 18: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 at 5-Mar-13 6:40am
   
can i use directly this code on qt
Richard MacCutchan at 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
0 Sergey Alexandrovich Kryukov 740
1 OriginalGriff 495
2 Maciej Los 355
3 Andy Lanng 284
4 CPallini 267
0 OriginalGriff 8,824
1 Sergey Alexandrovich Kryukov 8,247
2 CPallini 5,197
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2015
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