Update Cloudflare DNS with script

How your router connect to the internet? Using DHCP or PPPoE?

PPPoE: via /ip/address

:local wanif "pppoe-interface" 
...
:local ip4new [/ip/address/get [find where interface=$wanif] value-name=address];

DHCP: how does the router connect to the modem? If your router only had local ip (i.e. 192.168.x.x), you can’t get the public ip from your modem using that script. But there is a workaround, for example using public service like http://checkip.amazonaws.com/.

DHCP: via /tool/fetch

# :local wanif "dhcp-interface" (not used)
:local ip4new "0"

:local result [:tool fetch url="http://checkip.amazonaws.com/" as-value output=user]
:if ($result->"status" = "finished") do={
  :local ip4new [:pick ($result->"data") 0 ( [ :len ($result->"data") ] -1 )]
}

:if ([:len $ip4new] < 7) do={
  :log error "[Cloudflare DDNS] Could not get IPv4 for interface $wanif"
  :error "[Cloudflare DDNS] Could not get IPv4 for interface $wanif"
}

...