ROS 监测 Google 状态并自动切换 DNS
以下是一个使用 ROS 监测 Google 的状态并切换 DNS 的示例脚本:
:local google_ip
:local dns_ip
:local primary_dns '10.0.0.1'
:local secondary_dns '119.9.9.9'
# 获取 Google 的 IP 地址
:do {
:set google_ip [/ping count=1 address=8.8.8.8 interval=1]
:delay 1s
} on-error={:log error '无法连接到 Google'}
# 检查 Google 的状态码
:if ($google_ip->'received' > 0) do={
:log info 'Google 可访问'
# 获取当前 DNS 设置
:set dns_ip [/ip dns get value-name=servers]
# 检查 DNS 是否为 10.0.0.1
:if ($dns_ip != $primary_dns) do={
:log info '当前 DNS 不正确,切换到主 DNS'
/ip dns set servers=$primary_dns
} else={
:log info 'DNS 设置正确'
}
} else={
:log info 'Google 不可访问,切换到备用 DNS'
/ip dns set servers=$secondary_dns
}
请注意,这个脚本假设你已经正确配置了 ROS 的 DNS 设置。你需要将脚本中的 IP 地址和 DNS 设置改为适合你的网络环境的值。
另外,请注意在使用脚本之前,你需要在 ROS 中创建一个计划任务来定期执行该脚本。你可以使用以下命令创建计划任务:
/system scheduler
add name="google-status-check" interval=1m on-event="/import script-name.rsc"
将 script-name.rsc 替换为包含上述脚本的文件的实际名称。
原文地址: https://www.cveoy.top/t/topic/bAJG 著作权归作者所有。请勿转载和采集!