#ROS7 连接上外网后自动将外网IP地址发送到邮箱,DDNS不能用的时候也不怕了
#自动发送外网IP地址到邮箱
#上网接口名称
:local pppoe "pppoe-out1"
#设备名称
:local name "GHS-ROS"
#SMTP服务器
:local smtp "smtp.163.com"
#SMTP端口
:local smtpport "25"
#收件人账号
:local toemail "[email protected]"
#寄件人账号
:local myuser "[email protected]"
#寄件人密码
:local mypassword "123456"
#发送Email的主题
:local themes "ROS Email Assistant"
#发送内容
:local Contents "IP Address: "
:delay 3
#Email设置
/tool e-mail set server=$smtp port=$smtpport tls=no from=$myuser user=$myuser password=$mypassword
#获取接口IP地址
:local getip [ /ip address get [/ip address find interface=$pppoe] address ]
:global IPAddress [:pick $getip 0 [:find $getip "/" ] ]
#获取system版本
:global ROSVersion ("RouterOS Version: v" . [/system package get 1 version] )
#获取当前日期时间
:global Date ("Date:"[/system clock get date ])
:global Time ("Time:"[/system clock get time ])
#发送Email设置
/tool e-mail send to=$toemail subject=$themes body=("$name\n$Contents$IPAddress\n$ROSVersion\n$Date\n$Time")
#日志提醒
:log warning "外网地址已发送至($toemail)"
:log warning ("外网IP = " ."$IPAddress")
# by RouterOS 7.14.3
/system script
/system script
add dont-require-permissions=no name=ChangeIP_to_SendEmail owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":local pppoe "pppoe-out1"\r\
\n:local name "XXX-ROS"\r\
\n:local smtp "smtp.163.com"\r\
\n:local smtpport "25"\r\
\n:local toemail "[email protected]"\r\
\n:local myuser "[email protected]"\r\
\n:local mypassword "123456"\r\
\n:local themes "ROS Email Assistant"\r\
\n:local Contents "IP Address: "\r\
\n:delay 3\r\
\n/tool e-mail set server=\$smtp port=\$smtpport tls=no from=\$myuser user=\$myuser password=\$mypassword\r\
\n:local getip [ /ip address get [/ip address find interface=\$pppoe] address ]\r\
\n:global IPAddress [:pick \$getip 0 [:find \$getip "/" ] ]\r\
\n:global ROSVersion ("RouterOS Version: v" . [/system package get 1 version] )\r\
\n:global Date ("Date:"[/system clock get date ])\r\
\n:global Time ("Time:"[/system clock get time ])\r\
\n/tool e-mail send to=\$toemail subject=\$themes body=("\$name\\n\$Contents\$IPAddress\\n\$ROSVersion\\n\$Date\\n\$Time")\r\
\n:log warning "\CD\E2\CD\F8\B5\D8\D6\B7\D2\D1\B7\A2\CB\CD\D6\C1(\$toemail)"\r\
\n:log warning ("\CD\E2\CD\F8IP = " ."\$IPAddress")"
/ppp profile
add change-tcp-mss=yes name="ChangeIP to SendEmail" on-up="delay 3s\r\
\n:execute "ChangeIP_to_SendEmail"\r\
\ndelay 3s\r\
\n:execute "oray"\r\
\n"
/interface pppoe-client
add add-default-route=yes disabled=no interface=ether1 name=pppoe-out1 profile=\
"ChangeIP to SendEmail" use-peer-dns=yes user=123456
|