默认ping超时

时间:2013-06-18 07:13:13

标签: c# ping

ping的默认时间是多少?我使用下面的代码向tcp设备发送ping。 IPStatus什么时候会超时?

private static void ApplyPing(Topology.Runtime rt)
{
    try
    {
        if (rt.TcpClient != null)
        {
            string ip = rt.Ip;
            if (new Ping().Send(ip).Status != IPStatus.Success)
            {
                Service.WriteEventLog(string.Format("{0} ping error.", ip), EventLogEntryType.Warning);
                rt.Disconnect();
            }
        }
    }
    catch (ArgumentNullException ex)
    { 

    }
    catch (Exception ex)
    {
        Service.WriteEventLog(ex, EventLogEntryType.Error);
    }
}

谢谢。

1 个答案:

答案 0 :(得分:17)

来自MSDN herehere

  

该方法等待五秒钟以获取ICMP回送回复消息。如果它在那段时间内没有收到回复,则该方法返回,并且Status属性设置为TimedOut。

如果我们检查反射器,我们确实看到了:

public PingReply Send(string hostNameOrAddress)
{
    return this.Send(hostNameOrAddress, 5000, this.DefaultSendBuffer, null);
}
相关问题