怎么为ping命令设置超时时间

默认超时时间貌似是4000ms吧,我想把这个时间改成10ms,也就是延迟超过10ms即提示超时,我试过后面加-w 10但是完全没效果啊。

第1个回答  2019-02-11

w后面单位为秒。

        -w deadline

Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received. In this case ping does not stop after count  packet

are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network.

         -W timeout

Time to wait for a response, in seconds. The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.

追问

哦,我说的windows系统。 windows系统上怎么用呢?
其实我就想实现不停地ping个ip, 当延迟高于一定值时,执行一段命令。

追答

我手上没有windows环境,可以写个循环,不停的检查ping的结果,假如时延达到一定程度,就执行命令。执行完可以跳出循环,也可以继续循环。

刚网上找了一位同学写的代码,你可以参考下。他也用了-w参数,估计超时会导致命令errorlevel为1,就报错。

网页链接

第2个回答  2019-02-07
Ping的格式是这样使用的ping+空+网络地址+空+—t。