跳至正文
  • 12 views
  • 2 min read

dnspod更新脚本

新浪微博 豆瓣 QQ 百度贴吧 QQ空间

#PPPoE
:local pppoe "ROS_PPPoE"

#DNSPOD token
:local token "xxxxxxxxxxxxxxxxxxxxxxx"

#域名
:local domain "xxxx.xx"

#域名主机名
:local subdomain "www"
:local subdomain1 "mail"
:local subdomain2 "blog"

#以下不是专业人士请不要修改
#domain
:local dname ($subdomain.".".$domain)

#获取pppoe拨号ip
:local ipaddr [/ip address get [/ip address find interface=$pppoe] address]
:set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)]

#获取域名列表
: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]
:local record1 [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain1&record_type=A" as-value output=user]
:local record2 [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain2&record_type=A" as-value output=user]

#获取id和ip
: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 record ($record1->"data")
:set record [:pick $record [:find $record "\"records\":"] [:len $record]]
:local recordid1 [:pick $record ([:find $record "\"id\":\""]+6) [:find $record "\",\"ttl"]]
:local recordip1 [:pick $record ([:find $record "\"value\":\""]+9) [:find $record "\",\"en"]]

:set record ($record2->"data")
:set record [:pick $record [:find $record "\"records\":"] [:len $record]]
:local recordid2 [:pick $record ([:find $record "\"id\":\""]+6) [:find $record "\",\"ttl"]]
:local recordip2 [:pick $record ([:find $record "\"value\":\""]+9) [:find $record "\",\"en"]]

#更新ip地址
:if ($recordip!=$ipaddr) do={
/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"
:log info ("[".$dname."] ip update")
} else={
:log info ("[".$dname."] ip not update")
}

:local dname ($subdomain1.".".$domain)
:if ($recordip1!=$ipaddr) do={
/tool fetch url="https://dnsapi.cn/Record.Ddns" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain1&record_id=$recordid1&record_line_id=0&value=$ipaddr"
:log info ("[".$dname."] ip update")
} else={
:log info ("[".$dname."] ip not update")
}

:local dname ($subdomain2.".".$domain)
:if ($recordip2!=$ipaddr) do={
/tool fetch url="https://dnsapi.cn/Record.Ddns" http-data="login_token=$token&format=json&domain=$domain&sub_domain=$subdomain2&record_id=$recordid2&record_line_id=0&value=$ipaddr"
:log info ("[".$dname."] ip update")
} else={
:log info ("[".$dname."] ip not update")
}

发表回复