Code: Select all
# :log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ] // worked fine in ver6
:log info [/tool dns-update address=[:pick $ddnsip0 [:find $ddnsip "/"]] dns-server=$DNSServer name=$ddnshost key=$ddnspass key-name=$ddnsuser ttl=64 zone="user.changeip.net"]
Code: Select all
:global ddnsuser "info@user.com"
:global ddnspass "user21#"
:global ddnshost "user.changeip.net"
:local ddnsport 80
:global ddnscheckpoint
:local mydns [/ip dns get dynamic-servers]
:global DNSServer "170.178.190.178"
# [:pick $mydns 0]
:if ([:typeof $ddnscheckpoint] = "time") do={
:log info ("DDNS: Last check was " . ([/system clock get time] - $ddnscheckpoint))
} else={
:log info "DDNS: Cannot determine checkpoint, set now."
:global ddnscheckpoint ( [/system clock get time] - 1d )
}
# Get the current IP
:if ([/system clock get time] - $ddnscheckpoint > [:totime 180s] || [/system clock get time] - $ddnscheckpoint < [:totime 0s]) do={
:log info "DDNS: Performing remote IP detection."
/tool fetch address="ip.changeip.com" host="ip.changeip.com" src-path=("/?" . [/int eth get 0 mac-address ]) dst-path="ip.changeip.com.txt" mode=http port=$ddnsport
:global ddnscheckpoint [/system clock get time]
} else={
:log info "DDNS: Please be considerate and wait a few seconds longer."
:break
}
# Parse the IP address received from fetch script.
:global ddnslastip
:local html [/file get "ip.changeip.com.txt" contents]
:local ddnsip [:pick $html ([:find $html "<!--IPADDR="] + 11) [:find $html "-->"] ]
# Is it a valid IP and is it different than the last one?
:if ([:typeof [:toip $ddnsip]] = "ip" AND $ddnsip != $ddnslastip ) do={
:log info "DDNS: Sending UPDATE with $ddnsip"
# :log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ]
:log info [/tool dns-update address=[:pick $ddnsip0 [:find $ddnsip "/"]] dns-server=$DNSServer name=$ddnshost key=$ddnspass key-name=$ddnsuser ttl=64 zone="user.changeip.net"]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No update required."
}
}
Nigel