c# - 默认 ping 超时

标签 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);
    }
}

谢谢。

最佳答案

来自 MSDN herehere

The method waits five seconds for an ICMP echo reply message. If it does not receive a reply in that time, the method returns and the Status property is set to TimedOut.

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

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

关于c# - 默认 ping 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17162703/

相关文章:

python非特权ICMP

linux - 无法 ping 通 vmware 中的默认网关 linux

javascript - 运行 Node.js 命令不会产生任何输出并且不会退出

c# - HttpWebResponse.GetResponseStream() (似乎)毫无异常(exception)地失败

c# - MongoDB C# 2 驱动程序 - 无法从 BsonType 'String' 反序列化 'Double'

c# - Azure 应用服务简单端点的响应非常慢

android - 异步运行一个方法

loops - Ping 主机名列表并将结果输出到 powershell 中的 csv

c# - 异步套接字写入 - 发送操作是否有可能混淆? (.NET 套接字)

c# - C# 中如何确定变量类型是否支持给定运算符