复制代码 代码如下:
rem main.bat
@echo off
for /f "eol=; tokens=1,2* delims==" %%i in (ip.txt) do call :checkip %%i %%j 0
echo --------------------------------------------------------------
echo ----第一轮检查完毕,如果没有听到报警声,表示各ip都可以ping通----
echo ----如果有异常的ip,请再手动使用ping命令,以确认检查的正确性----
echo ---- 现在进行循环检查,每隔10000ms检查一个ip ----
echo --------------------------------------------------------------
:begin
for /f "eol=; tokens=1,2* delims==" %%i in (ip.txt) do call :checkip %%i %%j 10000
goto begin
:checkip
@echo off
ping %1 -n 1 | find "ttl=" >nul
if not errorlevel 1 echo %1(%2) status ok at %time%
if not errorlevel 1 goto next
ping %1 -n 1 -w 3000 | find "ttl=" >nul
if %errorlevel%==1 call :send %1 %2 else echo %1(%2) status ok at %time%
:next
sleep %3
goto end
:send
@echo off
echo %1(%2):::::status error at %time%:::::
for /f "eol=;" %%i in (user.txt) do net send %%i "error pinging %1(%2)." >nul
beep 1500 500
beep 500 500
beep 1500 500
beep 500 500
goto end
:end
192.168.0.1=集团网关
192.168.0.123=test
;user.txt,计算机名或ip,检测到网络不通时,发送消息给文中的用户
computername