本帖最后由 missll 于 2011-5-6 12:54 编辑
之前发过一个帖子询问 当时是直接检测PING值 有些不准确 所以另开帖提问,
目的: PING N个IP输出到文本,检测平均times值最少的 然后执行拨号动作, 例如:- Pinging 1.224.163.46 with 32 bytes of data:
-
- Reply from 1.224.163.46: bytes=32 time=406ms TTL=116
- Reply from 1.224.163.46: bytes=32 time=421ms TTL=116
- Reply from 1.224.163.46: bytes=32 time=405ms TTL=116
- Reply from 1.224.163.46: bytes=32 time=421ms TTL=116
- Ping statistics for 1.224.163.46:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 405ms, Maximum = 421ms, Average = 413ms
-
- Pinging 121.78.237.45 with 32 bytes of data:
-
- Reply from 121.78.237.45: bytes=32 time=326ms TTL=114
- Reply from 121.78.237.45: bytes=32 time=297ms TTL=114
- Reply from 121.78.237.45: bytes=32 time=296ms TTL=114
- Reply from 121.78.237.45: bytes=32 time=327ms TTL=114
-
- Ping statistics for 121.78.237.45:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 296ms, Maximum = 327ms, Average = 311ms
-
- Pinging 222.236.47.239 with 32 bytes of data:
-
- Reply from 222.236.47.239: bytes=32 time=383ms TTL=118
- Reply from 222.236.47.239: bytes=32 time=406ms TTL=118
- Reply from 222.236.47.239: bytes=32 time=390ms TTL=118
- Reply from 222.236.47.239: bytes=32 time=374ms TTL=118
-
- Ping statistics for 222.236.47.239:
- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
- Approximate round trip times in milli-seconds:
- Minimum = 374ms, Maximum = 406ms, Average = 388ms
复制代码 以上三个IP中 time最少的平均值是121.78.237.45,然后执行 rasdial.exe 121.78.237.45 name pass 来拨号连接。
之间的批处理是这样写的:- @echo off
- ::--------------------------------
- ping 1.224.163.46 -n 1 >>%TEMP%\ip.txt
- ping 121.78.237.45 -n 1 >>%TEMP%\ip.txt
- ping 222.236.47.239 -n 1 >>%TEMP%\ip.txt
- ::--------------------------------
- if exist %TEMP%\ip.txt (for /f "tokens=1,3,8 delims=m:=<> " %%a in (%TEMP%\ip.txt) do if /i "%%a"=="Reply" echo %%b=%%c
- ) else (echo not found %TEMP%\ip.txt)
- del /q %TEMP%\ip.txt
- pause
复制代码 它的缺点是 只PING了一个 不能更准确的显示平均时间, 因为只在含有“Reply”中寻找 用for /f 取出IP地址来
但是如果检测平均值 含有Average 字样的行没有IP 所以我不知道怎么显示了. 并且只是显示所有的PING值 我自己看哪个最少来手动拨号的.
如何取出这些平均值后如何逐步计算 一直到找出最小的呢? 以上是PING了3个,如果更多的时候怎么写. 请指点... |