C# Ping - 尝试了多少次?

C# Ping - how many attempts?

我正在使用 System.Net.NetworkInformation 库来 ping 一个 IP 地址来测试连通性。我想知道在失败之前它会尝试多少次?例如,如果您在 CMD 中执行 ping 操作,它会尝试 4 次。另外,如果它尝试多次尝试,当一些失败和一些通过时,它如何声明成功或失败?

我似乎在文档中找不到任何内容。

提前致谢!

每次调用 Ping.Send() 都会发送一个 ICMP 消息并阻塞,直到收到响应、发生错误或超时到期。

Ping.Send()方法将发送单个缓冲区并等待超时。

根据该参考资料:

This method sends a 32 Byte data buffer with the ICMP echo message. 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.

因此,要直接回答您的问题,需要 1 次尝试