中尉
- 注册时间
- 2011-1-24
- 金币
- 477 个
- 威望
- 1 个
- 荣誉
- 0 个
累计签到:11 天 连续签到:0 天 [LV.20]漫游旅程
|
本帖最后由 ice5221 于 2012-8-30 07:44 编辑
因为最近调试无线组网,需要不断检测各个设备的通断情况,所以写了这个批处理。 该批处理文件可以对网络内各个关键节点进行ping检测。 当出现故障时,有报警声发出,并且写入日志文件。 批处理运行时,随时显示错误记录总量,和最新故障时间和故障内容。 为了方便大家使用,我将简化后的批处理发出来,共享给大家。 目前版本,在使用前,需要手工设定33和34行的两个地址。 其实脚本还存在很多改进的空间,比如自动判断内网网关地址和自动判断外网网关地址; 比如简单设定变量地址后,对设定地址进行自动监测; 比如还有很多完善的空间。 最后,求回复! 哈哈 欢迎各种拍砖各种改进。
- @echo off d: :start rem 设定窗口标题 title 监测 %date% %time% rem 设定窗口大小 mode con cols=50 lines=15 rem title 正在判断当前网关地址 rem tracert /h 3 8.8.8.8>temp.log | findstr /i"\<.*"rem rem rem rem 间隔时间 rem echo.&ping -l 1 127.1 -l 1 -n 1>temp.log cls rem echo findstr/n . net.log|find /c /v""@echo off for /f"tokens=1 delims=:"%%i in ('findstr /n .* net.log') do set a=%%i echo 共有%a%条记录 set/a b=0 rem for /f"tokens=1 delims=:"%%i in ('findstr /n . net.log') do set/a b+=1 rem echo 总行数(扣除空行)是:%b% @echo off for /f"tokens=*"%%i in (net.log) do set str=%%i echo 最新记录 %str% rem for /f delims=. tokens=2-5 %%a in (a.txt) do echo %%a.%%b.%%c.%%d set lan=192.168.1.1 set wan=112.100.100.100 set date=%date /t% set time=%time /t% echo. echo. echo 私有网 通讯检测: ping -l 1 -n 2 %lan%>>temp.log set lan=%errorlevel% if %lan% EQU 0 echo.&echo 私有网正常&ping -l 1 127.1 -n 2>>temp.log if %lan% EQU 1 goto lan echo. echo. echo 互联网 通讯检测: ping -l 1 -n 2 %wan%>temp.log set wan=%errorlevel% if %wan% EQU 0 echo.&echo 互联网正常&ping -l 1 127.1 -n 2>>temp.log&goto start if %wan% EQU 1 goto wan :xunhuan goto start :lan echo title echo 私有网故障>>temp.log&title 私有网故障 echo %date% %time% 私有网故障>>net.log goto xunhuan :wan echo echo 互联网故障>>temp.log&title 互联网故障 echo %date% %time% 互联网故障>>net.log goto xunhuan
复制代码 |
|