It’ only my first successful trying.
Script worked in my simple home environment (just a single pppoe connection).
I doesn’t test it another situation. Anyway it could work for you.
There are still some :log info placed there to debug script
# Define User Variables
:global ddnsuser "USERNAME"
:global ddnspass "PASSWORD"
:global ddnshost "YOURHOSTNAME AT DDNS" #eg : pippo.ddns.info
# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version] )
# Define Local Variables
:local rt
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach rtf in=[/ip route find dst-address=0.0.0.0/0 active=yes] do={:set rt $rtf}
# Grab interface name from default route
:log info grab_if_name
:local if
:local ddnsifname
:foreach iff in=[/int find] do={:if (0<[:find [:tostr [/ip route get $rt gateway-status]] [:tostr [/int get $iff name]]]) do={:set if $iff;:set ddnsifname [/int get $if name];:set ddnsinterface [/int get $if name]}}
:log info $ddnsifname
# Grab the current IP address on that interface.
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No update required."
}
}
# End of script