I am trying to resolve a host name through a dynamic DNS service (No-IP). I have the script below but we are not having any luck. Any advice?
\
Delay for X seconds to allow hostname to resolve
:local delay 5
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”
}
}
}
/log info “[RESOLVE] - END”
:global comment
:global newip
/log info “[RESOLVE] - trying to resolve $comment from sub-script”
:set newip [:resolve $comment]
/log info “Address Resolved”
No-IP script
No-IP automatic Dynamic DNS update
#--------------- Change Values in this section to match your setup ------------------
No-IP User account info
:local noipuser “mrwieting85”
:local noippass “innova0511”
Set the hostname or label of network to be updated.
Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
To specify multiple hosts, separate them with commas.
:local noiphost “matty0511.no-ip.biz”
Change to the name of interface that gets the dynamic IP address
:local inetinterface “l2tp-in1”
#------------------------------------------------------------------------------------
No more changes need
:global previousIP
:if ([/interface get $inetinterface value-name=running]) do={
Get the current IP on the interface
:local currentIP [/ip address get [find interface=“$inetinterface” disabled=no] address]
Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = “/”) do={
:set currentIP [:pick $currentIP 0 $i]
}
}
:if ($currentIP != $previousIP) do={
:log info “No-IP: Current IP $currentIP is not equal to previous IP, update needed”
:set previousIP $currentIP
The update URL. Note the “\3F” is hex for question mark (?). Required since ? is a special character in commands.
:local url “http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP”
:local noiphostarray
:set noiphostarray [:toarray $noiphost]
:foreach host in=$noiphostarray do={
:log info “No-IP: Sending update for $host”
/tool fetch url=($url . “&hostname=$host”) user=$noipuser password=$noippass mode=http dst-path=(“no-ip_ddns_update-” . $host . “.txt”)
:log info “No-IP: Host $host updated on No-IP with IP $currentIP”
}
} else={
:log info “No-IP: Previous IP $previousIP is equal to current IP, no update needed”
}
} else={
:log info “No-IP: $inetinterface is not currently running, so therefore will not update.”
}