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")
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM