set ip=192.168.1.1
set i=1
set "str=Received = 0"
:start
rem ping -n 120 127.0.0.1 >nul 延长时间
ping %ip% -n 5 >c:\reply.txt
find "%str%" c:\reply.txt>nul && Goto Begin || Goto Delay
:Begin
del c:\1.txt
goto start
:Delay
if %i% GTR 3(
del c:\1.txt
shutdown /s /f
)else(
set /a i+=1
goto start
)
这个命令不知错在那里???求助........
对于老邝:gtr是大于.括号没有更不行.
对于yangyi0512这个不可行. 我基本上都要检测目标主机的开关状况.只有用BAT实用一些.
谢谢大家的支持!每两分钟检测目标主机一次,要是检测3次全不通,将关闭运行命令主机,只要通过一次,次数重置为1,下面代码能达到效果了,不知各位大侠有没有什么经典优化?!!!
@ Echo off
set ip1=192.168.1.1
set /a i=1
set /a a=1
:start
ping -n 115 127.0.0.1 >nul
ping %ip1% -n 2 >c:\reply.txt
ping -n 3 127.0.0.1 >nul
find /i "reply" c:\reply.txt>Nul&&Goto Begin
@ echo 第%i%次检测不到目标主机!
if %i% GTR 3 goto okover
set /a i+=1
goto start
:Begin
@ echo 第%a%次成功检测目标完成!
set /a a+=1
set /a i=1
goto start
:okover
shutdown /s /f