Click here to Skip to main content
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 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 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 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2014
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