我用的cloudflare 一样可以实现ddns
- #debug true/false
- :local CFDebug "false"
- #IPV4 use interface
- :global WANInterface4 "pppoe-out1"
- #TTL
- :local CFttl "120"
- #main zone
- :local CFzone "xxxxxx"
- #IPv4 domain
- :local CFdomain "xxxxxxx"
- :local CFdomainid "xxxxxxxxx"
- #CloudFlare???APIKEY
- :local CFemail "xxxxxx"
- :local CFtkn "xxxxx"
- :local CFzoneid "xxxxx"
- ################# intter value #################
- #ipv4
- :local currentIP ""
- :local resolvedIP ""
- :global WANip ""
- ################# get ip and set #################
- #get public IPv4
- :set currentIP [/ip address get [/ip address find interface=$WANInterface4 ] address];
- :set WANip [:pick $currentIP 0 [:find $currentIP "/"]];
- #get domain IPv4
- :set resolvedIP [:resolve $CFdomain];
- :log info ("CF: $resolvedIP ")
- ################# create CloudFlare API url (v4) #################
- #IPv4
- :local CFurl4 "https://api.cloudflare.com/client/v4/zones/"
- :set CFurl4 ($CFurl4 . "$CFzoneid/dns_records/$CFdomainid");
- ################# write debug indo to log #################
- :if ($CFDebug = "true") do={
- :log info ("CF: debug ture")
- :log info ("CF: domain $CFdomain")
- :log info ("CF: domain to IPv4 $resolvedIP")
- :log info ("CF: current IPv4 $WANip")
- :log info ("CF: use api v4 $CFurl4&content=$WANip")
- :if ($switchv6 = "true") do={
- :log info ("CF: ????IPv6 $resolvedIP6")
- :log info ("CF: ????IPv6 $WANip6")
- :log info ("CF: ???API??v6 $CFurl6&content=$WANip")
- };
- :put "Get CFdomainid: curl -X GET "https://api.cloudflare.com/client/v4/zones/$CFzoneid/dns_records" -H "X-Auth-Email: $CFemail" -H "X-Auth-Key: $CFtkn" -H "Content-Type: application/json" | python -mjson.tool"
- };
- ################# IPv4update and commpare #################
- :if ($resolvedIP != $WANip) do={
- :log info ("CF: update IPv4 domain to $CFdomain = $WANip")
- /tool fetch http-method=put mode=https url="$CFurl4" http-header-field="X-Auth-Email:$CFemail,X-Auth-Key:$CFtkn,content-type:application/json" as-value output=user http-data="{"type":"A","name":"$CFdomain","content":"$WANip","ttl":$CFttl,"proxied":false}"
- } else={
- :log info "CF: IPv4 address and public dns is same"
- }
- }
复制代码 |