Duck DNS Update Script for MikroTik 5.26

I would like to share the following Duck DNS Update Script for MikroTik 5.26 running on RB951G-2HnD.Please note that this script doesn’t work behind NAT and you can only fetch HTTP URL instead of HTTPS URL. You need the following policy read, write, policy, test for this script and remember to set a scheduler.

# Duck DNS Update Script for MikroTik

#--------------- Change Values in this section to match your setup ------------------

# Define User Variables for Duck DNS
:local ducktoken "your-token"
:local duckdomain "your-domain"
:local ddnshost "$duckdomain.duckdns.org"

# Change to the name of interface that gets the dynamic IP address
:local theinterface "PPPoE-interface"

#------------------------------------------------------------------------------------
# No more changes need

:local ipddns [:resolve $ddnshost];
:local ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]

:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("DuckDNS: No ip address on $theinterface .")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
      :set ipfresh [:pick $ipfresh 0 $i];
      } 
}
 
:if ($ipddns != $ipfresh) do={
    :log info ("DuckDNS: IP-DuckDNS = $ipddns")
    :log info ("DuckDNS: IP-Fresh = $ipfresh")
    :log info "DuckDNS: Update IP needed, Sending UPDATE...!"
    /tool fetch url="http://www.duckdns.org/update\?domains=$duckdomain&token=$ducktoken&ip=$ipfresh" dst-path=duckdns.txt
    :global ipddns $ipfresh
    :log info "DuckDNS: IP updated to $ipfresh!"
    } else={
     :log info "DuckDNS: dont need changes";
    }
}

Thank you.