mirror of
https://github.com/dudanov/mikrotik-cloudflare-ddns-scripts.git
synced 2025-05-09 11:57:24 +00:00
Create cloudflare6ddns
This commit is contained in:
parent
0f572d58ff
commit
f6ffc541ec
60
cloudflare6ddns
Normal file
60
cloudflare6ddns
Normal file
@ -0,0 +1,60 @@
|
||||
# Update Cloudflare DNS IPv6 address script
|
||||
# RouterOS version >= 6.44 is required
|
||||
|
||||
# ** CONFIGURE SECTION **
|
||||
|
||||
# IPv6 interface
|
||||
:local wanif "lan1"
|
||||
|
||||
# Cloudflare section
|
||||
:local email "e-mail"
|
||||
:local key "token"
|
||||
:local zoneId "zoneId"
|
||||
:local hostId "hostId"
|
||||
|
||||
# Domain hostname
|
||||
:local hostName "host.yourdomain.com"
|
||||
|
||||
# ** END OF CONFIGURE SECTION **
|
||||
|
||||
# Get WAN interface IPv6 address
|
||||
:global ip6wan
|
||||
:local ip6new [/ipv6 address get [/ipv6 address find interface=$wanif global] address]
|
||||
:set ip6new [:pick [:tostr $ip6new] 0 [:find [:tostr $ip6new] "/"]]
|
||||
|
||||
:if ([:len $ip6new] = 0) do={
|
||||
:log error "[Cloudflare DDNS] Could not get IPv6 for interface $wanif"
|
||||
:error "[Cloudflare DDNS] Could not get IPv6 for interface $wanif"
|
||||
}
|
||||
|
||||
:if ($ip6new != $ip6wan) do={
|
||||
|
||||
:log info "[Cloudflare DDNS] IPv6 address for interface $wanif has been changed to $ip6new."
|
||||
|
||||
:local url "https://api.cloudflare.com/client/v4/zones/$zoneId/dns_records/$hostId"
|
||||
:local header "X-Auth-Email: $email, X-Auth-Key: $key, content-type: application/json"
|
||||
:local data "{\"type\":\"AAAA\",\"name\":\"$hostName\",\"content\":\"$ip6new\",\"ttl\":120}"
|
||||
|
||||
# :log info "[Cloudflare DDNS] URL: $url"
|
||||
# :log info "[Cloudflare DDNS] HEADER: $header"
|
||||
# :log info "[Cloudflare DDNS] DATA: $data"
|
||||
:log info "[Cloudflare DDNS] Updating host $hostName address."
|
||||
|
||||
:local jsonAnswer [/tool fetch mode=https http-method=put http-header-field=$header http-data=$data url=$url as-value output=user]
|
||||
|
||||
:if ([:len $jsonAnswer] > 0) do={
|
||||
|
||||
/system script run "JParseFunctions"; global JSONLoads; global JSONUnload
|
||||
:local result ([$JSONLoads ($jsonAnswer->"data")]->"success")
|
||||
$JSONUnload
|
||||
|
||||
:if ($result = true) do={
|
||||
:log info "[Cloudflare DDNS] Successfully updated IPv6 address to $ip6new."
|
||||
:set ip6wan $ip6new
|
||||
} else={
|
||||
:log error "[Cloudflare DDNS] Error while updating IPv6 address."
|
||||
}
|
||||
} else={
|
||||
:log error "[Cloudflare DDNS] No answer from Cloudflare API."
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user