如何用批处理命令,使ping自动判断并显示状态

有3个IP:IP1,IP2,IP3。如何编程,自动按顺序ping每个IP,且在PING完一个IP后,自动判断并显示“通”或“不通”?

@echo off
setlocal enabledelayedexpansion
set IP1=127.0.0.1
set IP2=111.111.111.1
set IP3=111.111.111.2
set timeout=Request timed out.
for %%i in (%IP1% %IP2% %IP3%) do (
set result=true
ping %%i -n 1 | find "%timeout%">%temp%\MyTempPingFile.txt
for /F "delims=" %%j in (%temp%\MyTempPingFile.txt) do set result=false
if !result!==true (
echo ping %%i 通!) else (
echo ping %%i 不通!
)
)
del %temp%\MyTempPingFile.txt
pause
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-13
@echo off&color a&setlocal enabledelayedexpansion
for /f "usebackq skip=10 delims=" %%a in (%0) do (
for /f "delims=" %%b in ('ping -n 1 -w 1 %%a') do (
if %%b==请求超时。 set result=false
)
if !result!==false (echo %%a在线) else (echo %%a不在线)
set result=
)
echo 请按任意键退出…………&pause>nul&exit
请将你要ping的ip写在下面,每个ip一行:
124.111.23.12
124.111.23.11
124.111.23.7
124.111.23.8
相似回答