Board logo

标题: [网络连接] 求助测量网络:获取ping返回结果中的average平均时间大小 [打印本页]

作者: prairiewolf    时间: 2009-1-3 22:03     标题: 求助测量网络:获取ping返回结果中的average平均时间大小

ping www.yahoo.com.cn>c:\ping.txt
for /f "skip=9 tokens=4" %%a in (c:\ping.txt) DO set a= %%a
if a=4 goto pinging
elseif a=Maximum goto tel
:pinging
ping www.yahoo.com.cn>c:\ping.txt
for /f "skip=9 tokens=4" %%a in (c:\ping.txt) DO set a= %%a
if a=4 goto pinging
elseif a=Maximum goto tel
:tel
echo 网络通畅
pause
我想通过ping雅虎,得到ping.txt,截取部分内容,判断。想截时间,没截成,只好截别的不同字符,大家看看,怎么修改,最好。
作者: Batcher    时间: 2009-1-4 00:04

你想截哪个时间?
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\test>ping 127.1

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

作者: prairiewolf    时间: 2009-1-4 11:42

我ping的是雅虎,这里网络不好,有时好的时候,是73,不好的时候,网都打不开
我想截average=73ms,里的这个73,如果小于1000就跳转,大于1000,就退出
但是不知道怎么写代码

[ 本帖最后由 prairiewolf 于 2009-1-4 11:43 编辑 ]
作者: Batcher    时间: 2009-1-4 12:59     标题: 回复 3楼 的帖子

剩下的自己会写不?
  1. @echo off
  2. for /f "tokens=4 delims==" %%a in ('ping www.yahoo.com.cn') do (
  3.   set AveTime=%%a
  4. )
  5. set AveTime=%AveTime:~1,-3%
  6. echo %AveTime%
  7. pause
复制代码
建议:
1、下次提问,请在顶楼把自己的问题一次性描述清楚,最好给出实例。
2、到教学区好好看看关于for的教程。
作者: prairiewolf    时间: 2009-1-4 14:18

建议已经收到,我是前天要这个程序,才开始学dos,眼睛都快看花了,才憋出这段代码,
不过后面的代码还是不会写,
怎么判断网络通不通?有两种情况
1、网络太慢,时间超过1000ms
2、超时,request time out,那个变量里里是~1,3
还肯请大哥,把代码全贴一下,万分感谢.
对于您来说,这个只是分分钟的事,对我来说,至少也是一天的事(搞不巧还不一定呢),

[ 本帖最后由 prairiewolf 于 2009-1-4 15:08 编辑 ]




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2