Board logo

标题: [求助]判断网络连接状态 [打印本页]

作者: xycoordinate     时间: 2007-4-29 02:04    标题: [求助]判断网络连接状态

思路:
想用ping命令,判断网络连接
ping 192.168.0.2|find "Request timed out."

想在出现Request timed out.时,将当时的时间显示出来

怎么实现?

[ Last edited by xycoordinate on 2007-4-28 at 01:06 PM ]
作者: dikex     时间: 2007-4-29 02:33
ping默认会发送四个数据包,个人认为改为一个比较好

ping 192.168.0.2 /n 1 | find "Request timed out" 1>nul 2>nul && echo %time%
作者: xycoordinate     时间: 2007-4-29 03:37


  Quote:
Originally posted by dikex at 2007-4-28 13:33:
ping默认会发送四个数据包,个人认为改为一个比较好

ping 192.168.0.2 /n 1 | find "Request timed out" 1>nul 2>nul && echo %time%

谢谢!指点!

但是,我是想一直ping,查看丢包情况!
作者: lxmxn     时间: 2007-4-29 04:16
做一个循环有可以了。
@Echo off
:begin
ping 192.168.0.2 /n 1 /w 1000|find "Request timed out" 1>nul 2>nul &&echo %time%
goto begin

作者: xycoordinate     时间: 2007-5-1 05:25


  Quote:
Originally posted by lxmxn at 2007-4-28 15:16:
做一个循环有可以了。
@Echo off
:begin
ping 192.168.0.2 /n 1 /w 1000|find "Request timed out" 1>nul 2>nul &&echo %time%
goto begin

;)

感谢呀!
作者: flyinspace     时间: 2007-5-1 06:45
这样的话,最好把最后一句修改一下。。。


@Echo off
:begin
ping 192.168.0.2 /n 1 /w 1000|find "Request timed out" 1>nul 2>nul set count+=1&&echo [%count%]:%time%
goto begin

这样还可以获得时间和丢失包的次数。
作者: bingxiao20     时间: 2007-5-1 08:56
@Echo off
加了这个就什么都看不到了。。。
因为都没有定义 如何保存信息 到文件

还有 flyinspace 的这个我试了下 没有次数。。。只能显示时间了。。。。