I am trying to do IPSEC and one of the Mikrotiks has a static address aassoicted with it and the other is setup with a dynamic DNS through NO-IP.com.
Below is the script I am using but not having any luck
Any advice?
define variables
:global comment
:local newip
:local list
:local oldip
:local ipnohost
start logging
/log info “[RESOLVE] - START”
Loop through each entry in the address list
:foreach i in=[/ip firewall address-list find] do={
clear newip variable each time
:set newip “”
Get the first five characters of the list name
:set list [:pick [/ip firewall address-list get $i list] 0 5]
If they’re ‘host_’, then we’ve got a match - process it
:if ($list = “host_”) do={
Get the comment for this address list item (this is the host name to use)
:set comment [/ip firewall address-list get $i comment]
/log info “[RESOLVE] - checking $comment”
:set oldip [/ip firewall address-list get $i address]
/log info “[RESOLVE] - old ip: $oldip”
/log info “[RESOLVE] - attempting to resolve ip”
/log info “[RESOLVE] - noiphost: $newip”
:set newip [:resolve $no-iphost]
/log info “[RESOLVE] - resolved new ip: $newip”
This script does not wait for sub-script to resolve host names, so we need to delay for a time
:local counter 1
while ($counter <= $delay) do={
/log info “[RESOLVE] - waiting for hostname to resolve - attempt $counter”
:delay 1s
if length of new ip is greater than zero, break out of loop
:if ([:len $newip] > 0) do={
:set counter $delay
}
increment counter
:set counter ($counter + 1)
}
if new ip length is greater than zero, an ip was resolved
:if ([:len $newip] > 0) do={
/log info “[RESOLVE] - new ip: $newip”
if newip does not equal oldip
:if ($newip != $oldip) do={
/log info “[RESOLVE] - ip has changed, updating address list”
Set the address list entry accordingly
/ip firewall address-list set $i address=$newip
} else={
/log info “[RESOLVE] - new ip matches old ip, no change”
}
} else={
/log info “[RESOLVE] - did not get new ip, timed out”
}
}