Mikrotik RouterOS脚本定时发送ip至邮箱

  • RouterOS 6.42下测试成功的
  • SMTP服务器,端口,寄件人账号密码,收件人邮箱自定义
#上网接口名称
:local PPPInterface "自定义"
#设备名称
:local whoami "Hi,"
#SMTP服务器
:local SMTPServer "自定义"
#SMTP端口
:local SMTPPort "自定义"
#收件人账号
:local SendEmailTo "自定义"
#寄件人账号
:local Sender "自定义"
#寄件人密码
:local pwd "自定义"
#发送Email的主题
:local Themes "ROS Email Assistant"
#发送内容
:local Contents "IP Address: "
#返回SMTP服务器的IP
:local SMTPIP [:resolve $SMTPServer]
:delay 3
#Email设置
/tool e-mail set address=$SMTPIP port=$SMTPPort from=$Sender user=$Sender password=$pwd
#获取接口IP地址
:local getip [ /ip address get [/ip address find interface=$PPPInterface ] address ]
:global IPAddress [:pick $getip 0 [:find $getip "/" ] ]
#获取system版本
:global ROSVersion ("RouterOS Version: v" . [/system package get system version] )
#发送Email设置
/tool e-mail send to=$SendEmailTo from=$Sender subject=$Themes body=("$whoami\n$Contents$IPAddress\n$ROSVersion")
#日志提醒
:log warning "系统数据已备份,邮件已发送至($SendEmailTo)"
:log warning ("外网IP =" ."$IPAddress")

然后自己在scheduler中创建定时任务即可,
on event中就填写script的名字就可以了

听说经常点赞的同学技术进步的很快。

你可能感兴趣的:(Mikrotik,RouterOS)