将下面的文本另存为“断电关机.bat”
记得修改第1,2行的监测IP 推荐使用主交换IP和 网关IP
set ip1=192.168.1.220
set ip2=192.168.0.220
@echo off
@cls
@echo.
@echo.
@echo.
:duibi
@echo.
@echo 断电自动关机,取消关机请运行如下命令
@echo.
@echo ctrl + c
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
del /q b1.txt <nul
ping %ip1% > c:\01.txt
find "Lost = 4" c:\01.txt >b1.txt
set /a vars=0
for /f %%i in (b1.txt) do set /a vars+=1
if %vars% GEQ 2 (goto 2ip) else (goto duibi)
del /q b1.txt <nul
:2ip
@cls
echo 由于第一个检测地址断线,现在开始检测第二个设定IP。
del /q b12.txt <nul
ping %ip2% > c:\012.txt
find "Lost = 4" c:\012.txt >b12.txt
set /a vars=0
for /f %%i in (b12.txt) do set /a vars+=1
if %vars% GEQ 2 (goto guanji) else (goto di)
del /q b12.txt <nul
:guanji
echo 多个检测地址均断线 ,服务器将于1分钟后自动关机!
ping 127.0.0.1 -n 60 <nul
shutdown -s -c "由于计算机网络被中断,服务器被关闭。" -t 1"
exit
:di
echo 第二个设定IP正常在线
goto duibi
|
|