#GoDaddy DDNS Update Script
#Test with RouterOS 6.45.2 (Minimum version RouterOS 6.44)
#Date:2019/08/02
#The read,write,policy,test that all of these policies need to be set in script for the global variable

#ref1 https://www.instructables.com/id/Quick-and-Dirty-Dynamic-DNS-Using-GoDaddy/
#ref2 http://www.minitw.com/post/2018/05/09/routeros-ddns-namecheap

#Easy Test
# /tool fetch url=”https://api.godaddy.com/v1/domains/[domain]/records/A/[hostname]” http-method=put http-data=”[{\”data\”: \”10.10.10.10\”}]” http-header-field=”content-type: application/json,Authorization: sso-key [API_KEY]:[API_SECRET]”

#Create Schedule running
# /system scheduler add name=update-ddns interval=1m on-event=godaddy-ddns

#kye token format is [API_KEY]:[API_SECRET]
:local ddnkey “Authorization: sso-key [API_KEY]:[API_SECRET]”
:local ddnsdomain “[domain]”
:local ddnshostname “[hostname]”
:local ddnsinterface “pppoe-adsl”

#Use global variable to check if need update
:global ddnslastipADSL1
:global ddnsipADSL1 [/ip address get [/ip address find actual-interface=$ddnsinterface] address ]
:if ([:typeof [:global ddnslastipADSL1]] = nil ) do={ :global ddnslastipADSL1 0.0.0.0/0 } else={ :set ddnslastipADSL1 $ddnslastipADSL1 }

:if ([:typeof [:global ddnsipADSL1]] = nil ) do={
:log info (“DDNS: No ip address present on ” . $ddnsinterface . “, please check.”)
} else={
:if ($ddnsipADSL1 != $ddnslastipADSL1) do={
:local ipFormat [:pick $ddnsipADSL1 0 [:find $ddnsipADSL1 “/”]];
:log info “DDNS-Update use $ddnsinterface IP : $ipFormat”
:local ddnsurl “https://api.godaddy.com/v1/domains/$ddnsdomain/records/A/$ddnshostname”
:local ddnsipjson “[{\”data\”: \”$ipFormat\”}]”
:local result [/tool fetch url=$ddnsurl http-method=put http-data=$ddnsipjson http-header-field=”content-type: application/json,$ddnkey” as-value output=user]
:if ($result->”status” = “finished”) do={
:log info ($ddnshostname . “.” . $ddnsdomain ” Update IP ” . $ipFormat . ” Success”)
:global ddnslastipADSL1 $ddnsipADSL1
} else={
:log info (“DDNS Update Error”.$result->status)
}
} else={
:log info “DDNS: IP No Change”
}
}

本文链接:https://www.aiunk.com/897/

“游蕲水清泉寺,寺临兰溪,溪水西流。”

—— 苏轼《浣溪沙》
本站内容来源于互联网,所有转载、引用的文章、图片、视频等素材均来自网络公开渠道。我们对所转载的内容的版权和合法性不做任何保证。如果原作者或版权方认为本站内容侵犯其合法权益,敬请原作者或版权方及时联系我们,我们将在第一时间进行核实和处理,必要时删除相关内容。 本站的所有内容仅供个人学习与研究之用,不得用于任何商业用途。如需使用本站内容进行商业用途,请与原作者或版权所有者联系获取授权。 如有任何疑问或建议,请联系我们。