
[已處理]批處理如何檢測N個IP的最少PING值后計算出最小值最后由 missll 于 -5-6 12:54之前發(fā)過一個帖子詢問 當時是直接檢測PING值 有些不準確 所以另開帖提問,目的: PINGN個IP輸出到文本,檢測平均times值最少的 然后執(zhí)行撥號動作, 例如:
以上三個IP中 time最少的平均值是121.78.237.45,然后執(zhí)行 rasdial.exe 121.78.237.45 name pass 來撥號連接。之間的批處理是這樣寫的:nclick="copycode($('code0'));">復制代碼
- 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
它的缺點是 只PING了一個 不能更準確的顯示平均時間, 因為只在含有“Reply”中尋找 用for /f 取出IP地址來但是如果檢測平均值 含有Average 字樣的行沒有IP 所以我不知道怎么顯示了. 并且只是顯示所有的PING值 我自己看哪個最少來手動撥號的.如何取出這些平均值后如何逐步計算 一直到找出最小的呢? 以上是PING了3個,如果更多的時候怎么寫. 請指點...nclick="copycode($('code1'));">復制代碼
- @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

