Last active
September 2, 2024 13:47
-
-
Save kangarie/bad07d47c67e7320822bad41bd2cddca to your computer and use it in GitHub Desktop.
Mikrotik scheduler script to check AdGuardHome availability, by resolving to AGH server then change DNS if AGH is not resolving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:local curDNS [/ip dns get server] | |
:local gwDNS "192.168.2.1" | |
:local aghDNS "192.168.2.230" | |
:local oriDNS "8.8.8.8,8.8.4.4" | |
:local testDomain "www.google.com" | |
:local isDown "no" | |
:if ($curDNS = $aghDNS) do={ | |
:do { | |
:resolve $testDomain server=$aghDNS | |
} on-error={ | |
:set isDown "yes" | |
:log warning "AGH is seems down, checking number 1" | |
:delay 1 | |
} | |
:for i from=2 to=7 do={ | |
:if ($isDown = "yes") do={ | |
:do { | |
:resolve $testDomain server=$aghDNS | |
} on-error={ | |
:log warning "AGH is seems down, checking number $i" | |
:delay 1 | |
} | |
} | |
} | |
:if ($isDown = "yes") do={ | |
:log warning "AdGuardHome Offline" | |
/ip dns set servers=$oriDNS | |
/ip dhcp-server network set [find] dns-server=$gwDNS | |
} | |
} else={ | |
:do { | |
:resolve $testDomain server=$aghDNS | |
:log warning "AdGuardHome Online" | |
/ip dns set servers=$aghDNS | |
/ip dhcp-server network set [find] dns-server=$aghDNS | |
} on-error={} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
work fine. thanks