Windows目标服务器端口监测脚本微信通知

2016-08-25 浏览:3211
Windows目标服务器端口监测脚本微信通知
评论:(0)复制地址

通过检测目标服务器的端口状态,可以实现简单ping所不能实现的指定服务的监测,然后脚本可以实现短信或微信通知。


下面是一个检查邮件服务器的实例:https://github.com/zpblog/windows-port-checking

::邮件服务器工作状态监测通知脚本
::zpblog.cn
@echo off & setlocal enabledelayedexpansion
 
rem 要检测的IP和端口
set server_ip=192.168.1.8,218.218.218.218
set serverport=25,110
 
rem 模块化调用
set count=0
call :check
call :notice
::****其他代码略****
 
:check
rem ※端口检测模块--PortQry※
for /f "tokens=1,* delims=," %%i in ("!server_ip!") do (
  for %%a in (!serverport!) do (
    echo 正在检测 %%i 的 %%a 端口...
      rem 这是端口的检测代码:
      "C:\PortQryV2\PortQry.exe" -n %%i -e %%a | find ": LISTENING" >nul && (
        echo 【成功】:可以连接到 %%i:%%a
        ) || (        
        echo 【失败】:无法连通 %%i:%%a
        set status=!status! 【失败】:无法连通 %%i:%%a
        set /a count+=1
        )
      echo=
  )
  set server_ip=%%j
  goto check
)
goto :eof
:notice
rem ※判断是否通知--自己发挥吧※
if %count% GEQ 1 (
call :msg
call :mail
) else (
echo 一切正常
)
goto :eof
:mail
rem ※邮件通知模块--sendMail※
"C:\WINDOWS\system32\cmd.exe" /c C:\sendEmail\sendEmail.exe -f [email protected] -t [email protected] -u  Mail Server Fault %DATE:~0,10% %TIME% -m %status% -s smtp.qq.com:587 -xu [email protected] -xp asdfghjasdfghj
goto :eof
:msg
rem ※弹框通知模块--msg※
msg  %username% /time 1800 "邮件服务器出现故障,请立即协助通知系统管理员处理。联系电话:1234567890"
goto :eof
::****其他代码略****


代码比较简单,我相信大家应该能看懂。

里面用到两个EXE程序需要自行下载一下:sendEmail、PortQry


这边重点说一下,如何微信通知(短信通知也类似)。

微信通知:其实是通过微信中一个功能叫“QQ邮箱提醒”(我->设置->通用->功能)。然后通过发邮件到这个绑定的微信的QQ邮箱中,微信就会弹出消息提醒。是不是很Easy。你还可以指定只通知某一类的邮件 (*^__^*) 嘻嘻……

评论:(0)复制地址
发布:zpblog | 分类:Windows | Tags:脚本 邮件 端口

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。