Community discussions

MikroTik App
 
DiamondIT
just joined
Topic Author
Posts: 9
Joined: Mon Oct 16, 2017 10:04 pm

Disable/Enable firewall rule based on ping result

Thu Aug 23, 2018 9:50 am

Hi All,

Im looking to create a script to enable/disable rule if a internal server is unavailable based on ping is most likely the only option.

Could someone point me in the right direction, or tell me if its not the right way to go about this.

Regards

Michael
 
berzins
just joined
Posts: 10
Joined: Thu Apr 05, 2018 2:46 pm

Re: Disable/Enable firewall rule based on ping result

Thu Aug 23, 2018 10:39 am

Here's a base to work on:
:local alwaysRun true;

:while ($alwaysRun) do={
    
    :if ([ping address=10.155.0.255 count=5] = 0 ) do={
    
# disable the routes


} else={

# enable the routes

    }
}
Replace the IP address you want to ping and put the routes you want to enable/disable inside the script. Script will continuously run and ping 5 times - if no response, drop routes. If on next round of pings it pings, then it enables. You can add a delay at the start of the while loop to run every minute or so. If you want the script to keep working after reboot, then add it to Scheduler. More information can be found https://wiki.mikrotik.com/wiki/Manual:Scripting and https://wiki.mikrotik.com/wiki/Manual:System/Scheduler
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Disable/Enable firewall rule based on ping result

Sat Aug 25, 2018 3:49 pm

use netwatch instead
simple and easier

Who is online

Users browsing this forum: malks and 19 guests