Skip to content

Instantly share code, notes, and snippets.

@kangarie
Last active March 9, 2025 10:02
Show Gist options
  • Select an option

  • Save kangarie/bad07d47c67e7320822bad41bd2cddca to your computer and use it in GitHub Desktop.

Select an option

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
: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={}
}
@llity

llity commented Sep 2, 2024

Copy link
Copy Markdown

work fine. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment