Windows Server的远程登录邮件提示

工具地址:http://www.blat.net/

@echo off
:: blatt安装目录
set _extendDir=C:WindowsBlatfull
cd /d %_extendDir%
:: 设置消息
:: 标题
set s="Server-IP: x.x.x.x User login prompt"
:: 正文内容,采用文本预先编辑好,会显示到邮件正文部分
echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% >L_mail.txt
netstat -n -p tcp |findstr "1024" >>L_mail.txt
ping 127.1 >nul
set mail=%_extendDir%L_mail.txt
:: 接收人
set t=12345@qq.com
:: 发送人
set f=xxx@163.com
:: 163邮件服务器授权码
set pw=<填自己的>
:: 发送消息
blat %mail% -s %s% -to %t% -server smtp.163.com -f %f% -u %f% -pw %pw%

 # 对bat 文件进行加密参考  

通过改变进制的方法 16进制编辑软件,比如MiniHex

  

# 批处理创建计划任务

schtasks /create /tn "login_warring" /ru L fidc /tr C:WindowsBlatfullL_login.bat /sc onlogon

/tn 计划任务名称

/tr 计划任务路径

/sc 计划任务周期

Note: 因我用于监控用户登录,设置完成后,还需要手动修改【触发器】及任务历史记录,如做其他用途无需关注这2个选项

# 2020-7-31 优化版

@echo off
::Author: Loki 2020_07_31
::fixed ver0.1
::20200731_1 add port 1211
::20200731_2 add 获取服务器IP
::20200731_3 fixed 正则匹配端口
::20200805_4 fixed 增加quser;明确具体登录的用户
::20200805_5 add chcp;解决了产生的txt中文编码问题 ::获取服务器IP setlocal ENABLEEXTENSIONS
& set "i=0.0.0.0" & set "j=" for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do ( if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1") endlocal & set "ip=%i%" :: blatt安装目录 set _extendDir=C:WindowsBlatfull cd /d %_extendDir% :: 设置消息 :: 标题 set s="Server-IP: %ip% User login prompt" :: 正文内容,采用文本预先编辑好,会显示到邮件正文部分 echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2% >L_mail.txt whoami >>L_mail.txt netstat -n -p tcp |findstr -r "<3389>" >>L_mail.txt netstat -n -p tcp |findstr -r "<1211>" >>L_mail.txt chcp 65001 quser >>L_mail.txt chcp 1252 ping 127.1 >nul set mail=%_extendDir%L_mail.txt :: 接收人 set t=接受的邮箱@xxx.com set t2=接收的邮箱2@xxx2.com :: 发送人 set f=发送的邮箱@163.com :: 163邮件服务器授权码 set pw=XXXXX :: 发送消息 blat %mail% -s %s% -to %t% -server smtp.163.com -f %f% -u %f% -pw %pw% blat %mail% -s %s% -to %t2% -server smtp.163.com -f %f% -u %f% -pw %pw%

参考资料:

https://www.cnblogs.com/javabg/p/10418452.html

https://blog.csdn.net/huxiutao/article/details/89144937

原文地址:https://www.cnblogs.com/Cong0ks/p/12315877.html