要想检测到“请求超时”字样,那么每个ip只能ping一次,并重复100次,这样才能得到想要的信息,不过这样一来,日志结果看着就头疼了。如果不嫌看着头疼的话,就用下面代码吧!
@echo off
setlocal enabledelayedexpansion
set IPs=111.11.26.238,111.11.26.254,111.11.27.110,111.11.27.182,111.11.27.209
for %%a in (%IPs%) do call :PingIt "%%~a"
pause
exit
:PingIt
(for /l %%i in (1,1,100) do (
for /f "delims=" %%j in ('ping %~1 -n 1') do (
echo %%~j
echo "%%~j" | findstr /i "请求超时。" >nul 2>nul && set /a Count+=1 || set Count=0
if !Count! geq 5 goto :eof
)
))>E:\测试结果.txt
goto :eof