The indigoparadox Web Zone

Mikrotik Scripts

Back to projects

Web Zone Navigation

Related Web Zones

Other Web Zones

1. Replicate DNS

This script will gather the local static DNS records, SSH into another Mikrotik router, and add each one to that router. It can be used from a scheduled task as a lightweight DNS replication in environments with multiple Mikrotik routers, providing more than one DNS server to clients.

Before using this script, a SSH private key for the opposite router should be uploaded and added under Users / Private SSH keys. The private key should be created with ssh-keygen -m pem for the uploader to work properly!

1foreach i in=[/ip dns static find] do={
2 # Grab the properties of this entry.
3 :local dreg [/ip dns static get $i regex]
4 :local dcom [/ip dns static get $i comment]
5 :local dadd [/ip dns static get $i address]
6 :local dnam [/ip dns static get $i name]
7 :local dregSafe ""
9 # Go by name by default.
10 :local syncom "/ip dns static add address=$dadd name=$dnam"
11 :if ( [:len $dnam] = 0 ) do={
12 # Name len is 0 so use regex.
14 # Encode dollar signs or they'll mess up in transmission.
15 :for i from=0 to=([:len $dreg] - 1) do={
16 :local char [:pick $dreg $i]
17 :if ( $char = "\$" ) do={
18 :set $char "\\\$"
19 }
20 :set $dregSafe ( $dregSafe . $char )
21 }
23 # Construct remote command.
24 :set syncom "/ip dns static add address=$dadd regex=\"$dregSafe\""
25 }
27 # Execute command remotely.
28 :put $syncom
29 /system ssh-exec user=admin charle command=$syncom
31:log info "dns replication complete!"

2. Check URL Status

This script uses error reporting to provide a basic availability check for a URL. It would be useful to call this from a scheduled task. Please note that a 301 or other redirect counts as an error, so make sure to expand all URLs to their final expected destination!

Before using, you must replace with the URL to check and with the address to send reports to.

1do {
2 /tool fetch url="" as-value output=user
3} on-error={
4 /tool e-mail send to="" subject="WARNING DOWN" body=" is not available!"

Table of Contents

  1. Replicate DNS
  2. Check URL Status