📡 MikroTik Ping Script – Check If Host is Online or Offline


📋 Overview

This MikroTik script checks whether one or more hosts are online or offline using ping. If a host is unreachable, it sends an 📧 email notification.


🎥 Video Tutorial


🛠️ Script Details

#Log that the script has started
:log info ("Script started");
# Set how many ping attempts should be made
:local pingcount 3;
# Define IP addresses of hosts to check
:local host1 192.168.88.3;
# Host 1 check
:log info ("host 1 CHECK");
:local pingresult1 [/ping $host1 count=$pingcount];
# If host replies to ping
:if (pingresult1 > 0) do={
    :log info ("$pingresult1 of $pingcount PING Requests PASS");
    :log info ("$host1 ONLINE");
} else={
    # Send email if host is offline
    /tool e-mail send \
        to=your@email.com \
        subject="$pingresult1 of $pingcount PING Requests PASS. Can't ping $host1";
    :log info ("$host1 OFFLINE");
}
# Optional delay between checks
:delay 1;
:log info ("Delay 1 sec");

➕ Add More Hosts

To check multiple hosts, just repeat the logic with different host variables:

:local host2 192.168.88.4;
:log info ("host 2 CHECK");
:local pingresult2 [/ping $host2 count=$pingcount];
:if (pingresult2 > 0) do={
    :log info ("$host2 ONLINE");
} else={
    /tool e-mail send \
        to=your@email.com \
        subject="Can't ping $host2";
    :log info ("$host2 OFFLINE");
}

✉️ Email Configuration

Make sure email settings are configured under:

/tool e-mail set server=smtp.server.com port=587 start-tls=yes from="router@domain.com" user="your@email.com" password="yourpassword"


✅ Summary

This script is useful for:

  • Monitoring key hosts (servers, printers, cameras)
  • Getting alerts when something goes offline
  • Adding simple automation to your MikroTik setup

📦 Tip: Add this to Scheduler to run periodically!