110,535
社区成员
发帖
与我相关
我的任务
分享
static void displayReply() //显示结果
{
Ping p1 = new Ping(); //只是演示,没有做错误处理
PingReply reply = p1.Send("192.168.2.100");
StringBuilder sbuilder;
if (reply.Status == IPStatus.Success)
{
sbuilder = new StringBuilder();
sbuilder.AppendLine(string.Format("Address: {0} ", reply.Address.ToString()));
sbuilder.AppendLine(string.Format("RoundTrip time: {0} ", reply.RoundtripTime));
sbuilder.AppendLine(string.Format("Time to live: {0} ", reply.Options.Ttl));
sbuilder.AppendLine(string.Format("Don't fragment: {0} ", reply.Options.DontFragment));
sbuilder.AppendLine(string.Format("Buffer size: {0} ", reply.Buffer.Length));
Console.Out.WriteLine(sbuilder.ToString());
}
else if (reply.Status == IPStatus.TimedOut)
{
Console.Out.WriteLine("超时");
}
else
{
Console.Out.WriteLine("失败");
}
}