Thank you @skot
But the problem is that after applying what you posted. when internet is down , it changes ip to second one, but if the 2nd ip is also not working then it dont jump to 3rd or 4th,
in short, if the net is down, it simply changes ip to second one, but if the second ip is also not working , it dont jump to 3rd or 4th. it remain stuck at 2nd ip (may be due to status down variable setting)
How to solve it ? I want that if 2nd is also not working, then it should mvoe to 3rd or 4th whatever i working.
Current code is attached below.
# Script Starts here...
# Internet Host to be checked You can modify them as per required, JZ
:local host1 "8.8.8.8"
:local host2 "208.67.222.123"
# Do not modify data below without proper understanding.
:local i 0;
:local F 0;
:local date;
:local time;
:global InternetStatus;
:global InternetLastChange;
# PING each host 5 times
:for i from=1 to=2 do={
if ([/ping $host1 count=1]=0) do={:set F ($F + 1)}
if ([/ping $host2 count=1]=0) do={:set F ($F + 1)}
};
# If both links are down and all replies are timedout, then link is considered down
:if (($F=4)) do={
:if (($InternetStatus="UP")) do={
:log error "WARNING : The INTERNET link seems to be DOWN. Please Check";
:set InternetStatus "DOWN";
## ADD YOUR RULES HERE, LIKE ROUTE CHANGE OR WHAT EVER IS REQUIRED, Example is below ...
:log error "ISP LINK SEEMS TO BE DOWN, Changing IP Address /jz"
/ip address
:if ([get [find comment="ether1_wan_ip_1"] disabled] = false) do={
disable [find comment="ether1_wan_ip_1"]
enable [find comment="ether1_wan_ip_2"]
} else={
:if ([get [find comment="ether1_wan_ip_2"] disabled] = false) do={
disable [find comment="ether1_wan_ip_2"]
enable [find comment="ether1_wan_ip_3"]
} else={
:if ([get [find comment="ether1_wan_ip_3"] disabled] = false) do={
disable [find comment="ether1_wan_ip_3"]
enable [find comment="ether1_wan_ip_4"]
} else={
:if ([get [find comment="ether1_wan_ip_4"] disabled] = false) do={
disable [find comment="ether1_wan_ip_4"]
enable [find comment="ether1_wan_ip_1"]
}
}
}
}
:set date [/system clock get date];
:set time [/system clock get time];
:set InternetLastChange ($time . " " . $date);
} else={:set InternetStatus "DOWN";}
} else={
## If reply is received , then consider the Link is UP
:if (($InternetStatus="DOWN")) do={
:log warning "WARNING :The INTERNET link have been restored";
:set InternetStatus "UP";
/ip address
:if ([get [find comment="ether1_wan_ip_1"] disabled] = false) do={
enable [find comment="ether1_wan_ip_1"]
disable [find comment="ether1_wan_ip_2"]
} else={
:if ([get [find comment="ether1_wan_ip_2"] disabled] = false) do={
enable [find comment="ether1_wan_ip_2"]
disable [find comment="ether1_wan_ip_3"]
} else={
:if ([get [find comment="ether1_wan_ip_3"] disabled] = false) do={
enable [find comment="ether1_wan_ip_3"]
disable [find comment="ether1_wan_ip_4"]
} else={
:if ([get [find comment="ether1_wan_ip_4"] disabled] = false) do={
enable [find comment="ether1_wan_ip_4"]
disable [find comment="ether1_wan_ip_1"]
}
}
}
}
## ADD YOUR RULES HERE, LIKE ROUTE CHANGE OR WHAT EVER IS REQUIRED, Example is below ...
:local currentIP
:local externalInterface "ether1"
# get the current IP address from the external interface
:set currentIP [/ip address get [find interface="$externalInterface"] address]
# Strip netmask
:for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
:log warning "ISP LINK RE - CONNECTED with new WAN IP = $currentIP, Please check and confirm /jz"
}
}
:set date [/system clock get date];
:set time [/system clock get time];
:set InternetLastChange ($time . " " . $date);
} else={:set InternetStatus "UP";}
}
# Script Ends Here.
# Thank you