I want my router to change nat IP (to-addresses) whenever i execute a script.
I googled and i found a script but it seems like the script is not working.
Can someone check it for me and help?
Code: Select all
:global natAddressList;
:global currentNatAddress;
:global nextNatAddress;
:local i 0;
:set natAddressList ["10.20.20.2", "10.20.20.3", "10.20.20.4", "1020.20.4"]
:set currentNatAddress [/ip firewall nat get [find comment="NAT rule"] to-addresses]
:set i ($i + 1)
:if ($i > ( [:len $natAddressList] -1)) do={
:set i 0
}
:set nextNatAddress ($natAddressList->$i)
while ($nextNatAddress != $currentNatAddress) do={
if ([/ping $nextNatAddress count=1] = 0) do={
:set i ($i + 1)
:if ($i > ( [:len $natAddressList] -1)) do={
:set i 0
}
:set nextNatAddress ($natAddressList->$i)
} else {
:set currentNatAddress $nextNatAddress
/ip firewall nat set [find comment="NAT rule"] to-addresses=$currentNatAddress
}
}