一、 ROS 环境下Cloudflare API 更新动态IP地址脚本
Cloudflare是一家CDN,小弟很多域名都托管在CF上,代理转发速度不算最快,但免费、功能强、可配置程度高,非常推荐使用!
脚本内需要用到CF上多个参数,具体如何提取请参考本站另外的一篇文章
以下脚本直接复制到ROS -> System -> Scripts 新增的一条脚本Source框里
:global cfu do={\
:local cfi "Zone ID";\
:local cfr "Record ID";\
:local cfe "CF Account Email";\
:local cfk "Global_API_KEY";\
:local cfd "cfddns.iokiok.tk";\
:local currentIP [/ip address get [/ip address find interface=CT_dial ] address];\
:local cfa [:pick $currentIP 0 [:find $currentIP "/"]];\
:local cfp true;\
/tool fetch mode=https\
http-method=put\
url="https://api.cloudflare.com/client/v4/zones/$cfi/dns_records/$cfr"\ http-header-field="content-type:application/json,X-Auth-Email:$cfe,X-Auth-Key:$cfk"\ http-data="{\"type\":\"A\",\"name\":\"$cfd\",\"content\":\"$cfa\",\"proxied\":$cfp}"\ output=none\
}
:delay 1
$cfu
说明:
红字部分的参数在CF上提取并填入;这里特别说明cfe和cfr 的关系,cfr的值对应cfd ,即每个前缘的Record ID是不一样的,例如:abc.iokiok.tk 和 123.iokiok.tk 的cfr值是不一样的,这个要搞清楚。具体请看如何提取 Record ID 的文章!
蓝字部分 是指定是否开启CDN代理转发,开启CDN代理转发时,当访问cfddns.iokiok.tk时候是经过CDN代理再转发到你本地的公网IP地址,即解释出来的IP地址是CDN代理的IP地址;如关闭该选项,访问cfddns.iokiok.tk时直接解释是你现时的公网IP地址,如需关闭把蓝字部分删除即可。
最后在 ROS -> System -> Scheduler 里设置x分钟执行一次刚才刚才脚本即可。 [把脚本名称填入 On Event 里即可]
二、 ROS环境下changeip.com 更新动态IP地址脚本
以下脚本直接复制到ROS -> System -> Scripts 新增的一条脚本Source框里
:global ddnsuser "username"
:global ddnspass "password"
:global ddnshost "Dynamic domain name"
:global ddnsinterface "PPP Interface name"
:global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip
:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }
:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }
:if ([ :typeof $ddnsip ] = "nothing" ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No changes necessary."
}
}
红字说明:
PPP Interface name 这里是填入你pppoe拨号的名称,非Interfaces 里WAN口的名称,填错了抓不到公网IP地址。
最后跟前面的教程一下把该本脚本定时执行即可!