[Mikrotik Script] Cloudflare DNS API
:global currentIp
:local newIpCidr [:resolve myip.opendns.com server=208.67.222.222]
:local newIp [ :put "$newIpCidr" ]
:if ($newIp != $currentIp) do={
:local cfToken "**********"
:local cfZoneId "**********"
:local cfDnsId "**********"
:local dnsType "A"
:local dnsName "Your domain"
:local dnsTTL "1"
:local dnsProxied "false"
:local apiUrl "https://api.cloudflare.com/client/v4/zones/$cfZoneId/dns_records/$cfDnsId"
:local headers "Authorization: Bearer $cfToken"
:local payload "{\"type\":\"$dnsType\",\"name\":\"$dnsName\",\"content\":\"$newIp\",\"ttl\":$dnsTTL,\"proxied\":$dnsProxied}"
:do {
:local response [/tool fetch http-method="put" url=$apiUrl http-header-field=$headers http-data=$payload as-value output=user]
:if ($response->"status" = "finished") do={
:log info "DDNS - CloudFlare: changed $currentIp to $newIp"
:set currentIp $newIp
}
} on-error {
:log error "DDNS - CloudFlare: failed to change IP $currentIp to $newIp"
}
}