Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 15172

Scripting • Re: script to check if dns is running

$
0
0
This script checks the functionality of the server Pi.Hole with the address 192.168.188.245 and if it stops giving a response, it changes the main DNS server, and reverse. Clearing the cache is necessary to get the effect from Pi.Hole.
Code:
:local MONNAME "pi.hole";:local URI "https://api.telegram.org/bot<BotAPICode>/sendMessage?chat_id=<CHID>&text=";:local intDNS "192.198.188.245";:local extDNS "8.8.8.8";:local activeDNS ([/ip dns print as-value ] ->"servers");:do {    :if ( [:resolve $MONNAME server=$intDNS] != $activeDNS ) do={       :log error "Primary DNS is UP! again, switching to Pi-hole";      /ip dns set servers=$intDNS;      /ip dns cache flush#      /ip dhcp-client set use-peer-dns=no numbers=0      :local time [/sys clock get time];       /tool fetch url="$URI$MONNAME%20UP%20at%20$time" keep-result=no;    }} on-error={    :if ( $extDNS != $activeDNS ) do={      :log error "Internal DNS is DOWN! switching to external DNS";      /ip dns set servers=$extDNS;      /ip dns cache flush#      /ip dhcp-client set use-peer-dns=yes numbers=0      :local time [/sys clock get time];       /tool fetch url="$URI$MONNAME%20DOWN%20at%20$time" keep-result=no;    }}

Statistics: Posted by Kosmatik — Fri Jan 26, 2024 9:15 pm



Viewing all articles
Browse latest Browse all 15172

Trending Articles