This simple scripts are designed to implement DDNS feature using the Cloudflare API.
Scripts work only on RouterOS
version 6.44 and above.
Depends on Mikrotik JSON Parser project installed as system script with name JParseFunctions
.
Each script (IPv4 and IPv6) has a configuration area. Just insert your values.
First of all you need your Cloudflare API Token. Create the Cloudflare API Token, with DNS edit permission for your zone. Then grab your token, and follow the instructions. Keep the API Token safe.
You can go to your site's cloudflare dashboard to retrieve zone id, on the URL it is https://dash.cloudflare.com/$zone_id/$domain_name
, but DNS Record ID is only possible through REST API.
REST API methods List Zones and List DNS Records. Using any REST client (e.g. HTTPie, or curl), sending a request, you will receive the JSON answer with necessary Zone and DNS Record IDs.
Insert all variables in scripts and install in your RouterOS device.
Replace $api_token
with your api token.
curl --request GET \
--url https://api.cloudflare.com/client/v4/zones \
--header "Authorization: Bearer $api_token" \
--header "Content-Type: application/json"
Get dns record id. Replace $api_token
with your api token. And $zone_id
with zone id from above.
curl --request GET \
--url https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records \
--header "Authorization: Bearer $api_token" \
--header "Content-Type: application/json"
Tip
You can use jq to prettify json output.
You may add this script to system scheduler as periodically task.