Created
January 13, 2020 14:21
-
-
Save shenjunru/d38a2edebc8c44dbefe63cb3721a84ed to your computer and use it in GitHub Desktop.
DNSPod DDNS Updater on RouterOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#policy: read,test | |
#pppoe-interface | |
:local pppoe "pppoe-out1" | |
#dnspod-token | |
:local token "uid,api-toekn" | |
#dnspod-domain | |
:local domain "example.com" | |
:local subdomain "www" | |
:local dname ($subdomain.".".$domain) | |
#get-public-ip | |
:local ipaddr [/ip address get [/ip address find interface=$pppoe] address] | |
:if (0<[:find $ipaddr "/"]) do={ | |
:set ipaddr [:pick $ipaddr 0 [:find $ipaddr "/"]] | |
} | |
#get-dns-record | |
:local record [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain&record_type=A" as-value output=user] | |
:set record ($record->"data") | |
:set record [:pick $record [:find $record "\"records\":"] [:len $record]] | |
:local recordid [:pick $record ([:find $record "\"id\":\""]+6) [:find $record "\",\"ttl"]] | |
:local recordip [:pick $record ([:find $record "\"value\":\""]+9) [:find $record "\",\"en"]] | |
#set-dns-record | |
:if ($recordip!=$ipaddr) do={ | |
:set record [/tool fetch url="https://dnsapi.cn/Record.Ddns" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain&record_id=$recordid&record_line_id=0&value=$ipaddr" as-value output=user] | |
:set record ($record->"data") | |
:if (0<[:find $record "\"code\":\"1\""]) do={ | |
:log info ("DNSPOD [".$dname."] FORM [".$recordip."] TO [".$ipaddr."]") | |
} else={ | |
:log info ("DNSPOD [".$dname."] FAILED: ".$record) | |
} | |
} else={ | |
:log info ("DNSPOD [".$dname."] KEEP [".$recordip."]") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment