帮我在qt中找到traceroute [英] help me to find traceroute in qt
问题描述
请帮我找到qt c ++代码来查找ip的traceroute。我是开发人员和qt的新手我开发了以下代码,但是在c#中请帮助将其翻译成qt c ++
< pre lang =c#> public string Traceroute( string ipAddressOrHostName)
{
IPAddress ipAddress = Dns.GetHostEntry(ipAddressOrHostName).AddressList [ 0 ];
StringBuilder traceResults = new StringBuilder();
使用(Ping pingSender = new Ping())
{
PingOptions pingOptions = new PingOptions();
秒表stopWatch = 新秒表();
byte [] bytes = new byte [ 32 ];
pingOptions.DontFragment = true ;
pingOptions.Ttl = 1 ;
int maxHops = 30 ;
traceResults.AppendLine(
string .Format(
在最多{1}跳上追踪到{0}的路线:,
ipAddress,
maxHops));
traceResults.AppendLine();
for ( int i = < span class =code-digit> 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( 跟踪完成。); break ;
}
pingOptions.Ttl ++;
}
}
return traceResults.ToString() ;
}
阅读一些这些链接 [ ^ ]获取有用信息。
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();
}
Read some of these links[^] for useful information.
这篇关于帮我在qt中找到traceroute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!