ROS实现DNSPod的DDNS服务脚本

在ROS上实现DDNS服务

 一、登陆ROS,system ---> scripts,新建一个脚本,脚本内容粘贴在Source。

 

 二、脚本

  登陆DNSPod,点击头像--->密钥管理,新建一个新密钥,修改下方脚本代码即可

#PPPoE
:local pppoe "pppoe-ddns"

#DNSPOD token
:local token "id,token"

#域名
:local domain "domain.com"

#域名主机名
:local subdomain "subdomain"


#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]

#获取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"]]

#更新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")
}

 

posted @ 2020-08-31 14:43  夜半歌声断  阅读(2483)  评论(0编辑  收藏  举报