当前位置: 移动技术网 > IT编程>网络>Dos/Bat > 计算机/网络设备状态监测脚本 批处理

计算机/网络设备状态监测脚本 批处理

2017年12月12日  | 移动技术网IT编程  | 我要评论
以前自己写的一个监控脚本,每隔10秒使用ping命令检查一个ip列表中的ip,如果不通,则通过messenger消息发送,并使用beep发出报警声。需要文件sleep.exe(可到网上下一个)、beep.exe(自己用delphi写的,不必需,代码可去掉,也可以去网上找一个),再建立文件ip.txt,user.txt,运行脚本即可。

复制代码 代码如下:

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 
;ip.txt,关键ip,一行一个ip,等号后面可输入名称
192.168.0.1=集团网关
192.168.0.123=test

;user.txt,计算机名或ip,检测到网络不通时,发送消息给文中的用户
computername

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网