首先要在DNSPOD申请API-Token,并通过API-Token获取Record_id:
可以使用curl命令快速获取record_id:
curl -X POST https://dnsapi.cn/Record.List -d "login_token=1****2,de06f**********fa5ce07&format=json&domain=c-o.ltd&sub_domain=@&record_type=A"
获取本机PPPoE网卡IP
{
local ednsinterface "pppoe-out1"
local status [/interface get [/interface find name=$ednsinterface] running]
if ($status!=false) do= {
local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
local ednsip [:pick $ednsiph 0 [:find $ednsiph "/"]]
put $ednsip
}
}
通过DNSPOD-API获取记录当前解析IP:
{
local logintoken "11**12,de06****************03f9afa5ce07"
local domain "c-o.ltd"
local subdomain "@"
local data [/tool fetch url="https://dnsapi.cn/Record.List"\
http-method=post output=user as-value\
http-data=("login_token=$logintoken&format=json&domain=$domain&sub_domain=$subdomain&record_type=A")]
# fetch获取的data为array类型,还包含其他数据,把返回值从中取出
local data [pick $data 0];
# 利用find函数查询返回值中是否有本机IP
if ([find $data "8.8.8.8"]) do= {
put "found"
} else= {
put "not found"
}
}
# 汇总:先获取本机IP,再获取DNSPOD侧IP,若不一致则更新:
{
local logintoken "11**12,de06****************03f9afa5ce07"
local domain "c-o.ltd"
local subdomain "@"
local recordid ""
# 获取本机IP(pppoe-out1)
local ednsinterface "pppoe-out1"
local status [/interface get [/interface find name=$ednsinterface] running]
if ($status!=false) do= {
local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
local ednsip [:pick $ednsiph 0 [:find $ednsiph "/"]]
# put $ednsip
}
local data [/tool fetch url="https://dnsapi.cn/Record.List"\
http-method=post output=user as-value\
http-data=("login_token=$logintoken&format=json&domain=$domain&sub_domain=$subdomain&record_type=A")]
# fetch获取的data为array类型,还包含其他数据,把返回值从中取出
local data [pick $data 0];
# 利用find函数查询返回值中是否有本机IP,若没有则先更新
if ([find $data $ednsip] != nil) do= {
# put "found"
} else= {
/tool fetch url="https://dnsapi.cn/Record.Modify"\
http-method=post output=none\
http-data=("login_token=$logintoken&format=json&domain=$domain&record_id=$recordid&sub_domain=$subdomain&record_type=A&record_line_id=0&value=$ednsip")]
}
}
最终导入schedule时应去除中文,以免识别错误:
{
local logintoken "11**12,de06****************03f9afa5ce07"
local domain "c-o.ltd"
local subdomain "@"
local recordid "554754907"
local ednsinterface "pppoe-out1"
local status [/interface get [/interface find name=$ednsinterface] running]
if ($status!=false) do= {
local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
globa ednsip [:pick $ednsiph 0 [:find $ednsiph "/"]]
}
local data [/tool fetch url="https://dnsapi.cn/Record.List"\
http-method=post output=user as-value\
http-data=("login_token=$logintoken&format=json&domain=$domain&sub_domain=$subdomain&record_type=A")]
local data [pick $data 0];
if ([find $data $ednsip]) do= {
# put "found"
} else= {
local data [/tool fetch url="https://dnsapi.cn/Record.Modify"\
http-method=post output=user\
http-data=("login_token=$logintoken&format=json&domain=$domain&record_id=$recordid&sub_domain=$subdomain&record_type=A&record_line_id=0&value=$ednsip")]
# put "updated"
}
}