Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #No-IP automatic Dynamic DNS update for RouterOS v6.x
- #--------------- Change Values in this section to match your setup ------------------
- # No-IP User account info
- :local noipuser "YOUR_LOGIN_TO_NO_IP"
- :local noippass "YOUR_PASSWORD_TO NO_IP"
- # Workaround - find IP of a single dynamic host for IP prior to update
- # Only enter a single hostname for this variable
- :local previphost "YOUR_HOST.no-ip.org"
- # 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 "YOUR_HOST.no-ip.org,YOUR_HOST.no-ip.com"
- # Change to the name of interface that gets the dynamic IP address
- :local inetinterface "YOUR_WAN_INTERFACE_NAME_f.e_port2_public"
- #------------------------------------------------------------------------------------
- # No more changes need
- :global previousIP
- :if ([/interface get $inetinterface value-name=running]) do={
- # get the current IP address from the internet (in case of double-nat)
- /tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="dyndns.checkip.html"
- :local result [/file get dyndns.checkip.html contents]
- # parse the current IP result
- :local resultLen [:len $result]
- :local startLoc [:find $result ": " -1]
- :set startLoc ($startLoc + 2)
- :local endLoc [:find $result "</body>" -1]
- :local currentIP [:pick $result $startLoc $endLoc]
- :log info "Update NO-IP.com: currentIP = $currentIP"
- # 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]
- # }
- # }
- # Get your previous IP address
- :set previousIP [:resolve $previphost]
- :if ($currentIP != $previousIP) do={
- :log info "No-IP: Current IP $currentIP is not equal to previous IP $previousIP, 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 "https://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=https keep-result=no;
- :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."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement