Internet Connectivity Monitor Script requierd [SOLVED]

Here is the code for 2 websites, it can be easily modified to test more addresses. It is rather simple and could be done better but it might help you.
Please be aware that the script expects the InternetStatus to be already set, meaning it runs the ‘#do something commands’ just when the status changes , if you run the script for the first time it just populate the variable but would not action.

:local i 0;
:local F 0;
:local date;
:local time;


:local webpage1	"8.8.8.8"
:local webpage2	"www.google.com"

:global InternetStatus;
:global InternetLastChange;

:for i from=1 to=5 do={
	if ([/ping $webpage1 count=1]=0) do={:set F ($F + 1)}
	if ([/ping $webpage2 count=1]=0) do={:set F ($F + 1)}
	:delay 1;
};
				
:if (($F=10)) do={
	:if (($InternetStatus="UP")) do={
		:log info "WARNING : The INTERNET service's gone DOWN";
		:set InternetStatus "DOWN";

##		do something

				
		:set date [/system clock get date];
		:set time [/system clock get time];
		:set InternetLastChange ($time . " " . $date);
				
	} else={:set InternetStatus "DOWN";}
} else={
	:if (($InternetStatus="DOWN")) do={	
		:log info "WARNING : The INTERNET service's gone UP"; 
		:set InternetStatus "UP";

##		do something

		:set date [/system clock get date];
		:set time [/system clock get time];
		:set InternetLastChange ($time . " " . $date);
				
	} else={:set InternetStatus "UP";}
}

I am facing following issue.
After the script runs, it do logs, but no variable is displayed in VARIABLES section of the script.
The previous version of the script which check s only single host was making variables fine.
1.JPG

You can not ping http://www.google.com on script, you must resolve first the DNS to IP…

Is strange: where you have put the script?

I am not using google.com, I am using PUBLIC IP addresses for test purpose like isp gateway IP and 8.8.8.8.
I add the script in SCRIPT section like I use to add other scripts which works fine.

UPDATE: I tested the same script on another RB, and it worked fine. So probably something is wrong in test RB (x86 version)

the line on the script can be fix with:
:local website2 value=[:resolve domain-name=“www.google.com” server=8.8.4.4 server-port=53];

Thanks for the tip rextended, for some reason it also works with domain name and it resolves the IP automatically

I hope new RouterOS version can use dynamically the DNS name instead only IP… :stuck_out_tongue_winking_eye:

P.S.:

I specify the part on red
:local website2 value=[:resolve domain-name=“www.google.com” server=8.8.4.4 server-port=53];

because on this way, it work (obviously if 8.8.4.4 are reachable) without have previously configured correctly DNS on routerboard :wink:

thank you both of you :slight_smile:

Hi

I am happy to announce that I integrated this script and failover working from cable modem to lte_modem
for more details read also here: http://forum.mikrotik.com/t/ppp-out-default-route-disappears-1-second-after-interface-is-enabled/138480/1

The big goal in my config was that I need to reach the Webserver in my DMZ behind the mikrotik from outside and it WORKS!!!

I needed two years to finish with this hobby task :slight_smile: haha YES!!!