Mikrotik RouterOS script sends ip to mailbox regularly

  • Tested successfully under RouterOS 6.42
  • SMTP server, port, sender account password, recipient mailbox customization
#上网接口名称
: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")

Then you can create a timed task in the scheduler yourself,
and fill in the name of the script in the on event.

I heard that the technology of the students who often likes is progressing rapidly.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124695&siteId=291194637