«

RouterOS v7 DNSPod DDNS更新脚本

myluzh 发布于 阅读:23 RouterOS


0x01 关于参数解释

login_token:用于鉴权的 API Token。完整的 API Token 是由 ID,Token 组合而成的,用英文的逗号分割。获取地址(https://console.dnspod.cn/account/token/token),我的账号->api秘钥->DNSPod TOKEN。
domain_id:域名ID。我的域名->解析设置->Domain ID。
record_id:记录ID,需要在解析记录,自定义列表字段,勾选记录ID,就会出来。
record_line_id:线路id,0就是默认
sub_domain:sub_domain 主机记录值。

0x02 routeros7 dnspod ddns更新脚本

版本 MikroTik RouterOS 7.20.6 可用
forceUpdate flase:强制更新
forceUpdate true:只有公网IP发生变动才触发更新。

:local loginToken "606300,b672ff658xxxxxxxx189"
:local domainId "82385081"
:local recordId "2145599441"
:local subDomain "myddns1"
:local recordLineId "0"
:local wanInterface "pppoe-out-dx"
:local forceUpdate flase
:global LastDDNSIP

:local currentIP ""
:do {
    /interface pppoe-client monitor $wanInterface once do={
        :set currentIP $"local-address"
    }
} on-error={
    :log error "DDNS: Failed to get IP"
    :error "Stop"
}

:if ([:len $currentIP] = 0) do={
    :log error "DDNS: IP is empty"
    :error "Stop"
}

:if ($LastDDNSIP != $currentIP || $forceUpdate = true) do={

    :log info "DDNS: Update Triggered ($LastDDNSIP -> $currentIP) [Force: $forceUpdate]"

    :local postData "login_token=$loginToken&format=json&domain_id=$domainId&record_id=$recordId&record_line_id=$recordLineId&sub_domain=$subDomain&value=$currentIP"

    :do {
        /tool fetch url="https://dnsapi.cn/Record.Ddns" mode=https http-method=post http-data=$postData keep-result=no
        :set LastDDNSIP $currentIP
        :log info "DDNS: Update Success"
    } on-error={
        :log error "DDNS: Update Failed"
    }

} else={
    #:log info "DDNS: No change."
}

0x03 其他

# curl测试
curl -X POST https://dnsapi.cn/Record.Ddns -d "login_token=585827,2ac011d3a1165e0fbd9d3051103b18c&format=json&domain_id=82387087&record_id=2145599428&record_line_id=0&sub_domain=myddns1"

参考文章:
添加记录 https://docs.dnspod.cn/api/add-record/
利用DNSPod实现DDNS https://blog.csdn.net/PengWon/article/details/142480444

routeros ddns ros7 dnspod


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/ros/557.html
文章标题:《RouterOS v7 DNSPod DDNS更新脚本