本脚本用于ROS更新IP至DDNS,适用于dyndns.org。
#https://www.haiyun.me
#设置变量
:local ddnsuser "onovps"
:local ddnspass "onovps"
:local ddnshost "onovps.dyndns.org"
:local ddnsinterface "pppoe-out1"
#设置IP变量
:global newip
:global lastip
:if ([ :typeof $lastip ] = nil ) do={ $lastip "0" }
#获取当前外网IP
:set newip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
#去掉IP的网段
:set newip [:pick $newip 0 [:find $newip "/"]]
#判断新旧IP是否相同
:if ([ :typeof $newip ] = nil ) do={
:log info ("DynDNS: " . $ddnsinterface . "没有获取到外网IP")
} else={
:if ($newip != $lastip) do={
:log info ("DynDNS:" . $ddnsinterface . "更新IP为" . $newip)
:local str "/nic/update?hostname=$ddnshost&myip=$newip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
:delay 1
:local str [/file find name="DynDNS.$ddnshost"];
/file remove $str
#设置新IP为上次IP,供下次调用
:global lastip $newip
}
}