Community discussions

MikroTik App
 
User avatar
ConnectiviaSrl
just joined
Topic Author
Posts: 7
Joined: Sat May 19, 2012 11:04 am
Location: Naples Area / Italy
Contact:

Dynamic DNS Update Script for No-IP DNS behind nat

Mon May 21, 2012 12:06 pm

Hi folks

we use the dyndns service from http://www.no-ip.com on our behind nat Mikrotik Router distributed around Connectivia sites.
For this reason we delivered (tested on RouterOs 5.x) a new one script as a merge of the two faboulous scripts already available on wiki.mikrotik.com to have a dyndns update script
specific for No-IP dyndns service when Mkt devices are behind nat. Thanks to the creator of changeip script published on Wiki page http://wiki.mikrotik.com/wiki/Scripts- We hope it's no problem to use the base or some parts .


Here you have the script :
#Dynamic DNS Update Script for No-IP DNS behind nat
# Set needed variables
:local username "uzername"
:local password "pazzword"
:local host "dreammachine.no-ip.org"

:global previousIP

# print some debug info 
:log info ("Update No-IP DNS: username = $username")
:log info ("Update No-IP DNS: hostname = $host")
:log info ("Update No-IP DNS: previousIP = $previousIP")

# 
# behind nat - get the publòic address using dyndns url http://checkip.dyndns.org 

/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 "No-IP DNS: currentIP = $currentIP"

:if ($currentIP != $previousIP) do={
       :log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
       :set previousIP $currentIP
       :local url "http://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP&hostname=$host"
       :log info "No-IP DNS: Sending update for $host"
       /tool fetch url=$url user=$username password=$password mode=http dst-path=("no-ip_ddns_update.txt")
       :log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
}
else={
   :log info "No-IP: update not needed "
}
# end 
RouterOs Team @ Connectivia S.r.l
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26287
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Wed Jun 06, 2012 2:30 pm

Thanks! Can you post this in our wiki?
 
nicholwee
just joined
Posts: 11
Joined: Sun Dec 04, 2011 6:00 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Sun Jun 10, 2012 5:34 am

Great work! Thank you! :)
 
nicholwee
just joined
Posts: 11
Joined: Sun Dec 04, 2011 6:00 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Sun Jun 10, 2012 5:43 am

Hi! I tested this script to work on RB450G with 5.17. However, just wanted to clarify whether we need to specify the gateway interface for this to be more effective. Because in my previous script, the gateway interface was specified. Thanks.
 
Ham
just joined
Posts: 18
Joined: Thu Oct 27, 2011 1:27 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Tue Jun 12, 2012 6:31 am

Thanks you for writing this script nicholwee, it's been working a treat.
 
screenname
just joined
Posts: 1
Joined: Tue Jun 19, 2012 6:22 pm

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Tue Jun 19, 2012 6:27 pm

Thank you for the script and a suggestion for enhancement. Because my IP address don't change often, I still get the monthly e-mail remind me to log into my no-ip.com account. Can the script be changed so it will update with a dummy IP first then the real one every X days?
Thank you again.
 
User avatar
saintofinternet
Forum Veteran
Forum Veteran
Posts: 768
Joined: Thu Oct 15, 2009 3:52 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Sat Aug 24, 2013 6:05 am

not working in ver 6.0

the files are not getting created.... nor is the no-ip page getting updated...
 
fuba
just joined
Posts: 3
Joined: Fri Jul 04, 2014 5:08 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Fri Jul 04, 2014 5:14 am

I got this to work on ver. 6.15.
Found it here
#Dynamic DNS Update Script for No-IP DNS behind nat
# Set needed variables
:local username "your no-ip user login"
:local password "your no-ip password"
:local host "your no-ip host name"
:global previousIP
# print some debug info
:log info ("Update No-IP DNS: username = $username")
:log info ("Update No-IP DNS: hostname = $host")
:log info ("Update No-IP DNS: previousIP = $previousIP")
#
# behind nat - get the public address using dyndns url http://checkip.dyndns.org
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:delay 2
:local result [/file get dyndns.checkip.html contents]
:log info "dyndns result = $result"
# 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 "No-IP DNS: currentIP = $currentIP"
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
:set previousIP $currentIP
:local url "http://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
/tool fetch url=$url user=$username password=$password mode=http dst-path=("no-ip_ddns_update.txt")
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
:delay 2
:local result [/file get "no-ip_ddns_update.txt" contents]
:log info "Update Result = $result"
} else={
:log info "No-IP: update not needed "
}
# end
 
kasser010
just joined
Posts: 2
Joined: Fri Jun 19, 2015 9:18 am

Re: Dynamic DNS Update Script for No-IP DNS behind NAT

Fri Jun 19, 2015 10:55 am

Hi,

I've created a newer Updater which includes the following features:

[*]using IP Cloud to get the public IP (requires ROS v6.14)
[*]updating the host via https
[*]automatically updates every 3 minutes
[*]does not create any files


Just copy the following Code into a textfile
edit the USER,PASS and HOST
and paste it into the CLI and it will create the Updater:

ROS Version >= 6.27
1. Add a script with read,write,test policy called no-ip_update:
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"
:global previousIP
# behind NAT - using MikroTik IP Cloud feature
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info "No-IP DNS: currentIP = $currentIP"
#compare IPs
:if ($currentIP not $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
#current IP overrides previous
:set previousIP $currentIP
:local url "https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
2. Put the following code into the CLI:
/ip cloud set ddns-enabled=yes
/system scheduler add name=no-ip-updater disabled=no interval=3m policy=read,write,test  on-event=no-ip_update

ROS Version 6.14 to 6.26
1. Add a script with read,write,test policy called no-ip_update:
#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"
:global previousIP
# behind NAT - using MikroTik IP Cloud feature
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info "No-IP DNS: currentIP = $currentIP"
#compare IPs
:if ($currentIP not $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
#current IP overrides previous
:set previousIP $currentIP
:local url "https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP DNS: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end
2. Put the following code into the CLI:
/ip cloud set enabled=yes
/system scheduler add name=no-ip-updater disabled=no interval=3m policy=read,write,test  on-event=no-ip_update
 
djynny
just joined
Posts: 11
Joined: Thu Jun 30, 2011 9:50 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Wed Dec 09, 2015 6:31 pm

ROS Version >= 6.27
1. Add a script with read,write,test policy called no-ip_update:
Code: Select all

#Dynamic DNS Update Script for No-IP DNS behind NAT
# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"
:global previousIP
# behind NAT - using MikroTik IP Cloud feature
#current IP
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]
:log info "No-IP DNS: currentIP = $currentIP"
#compare IPs
:if ($currentIP not $previousIP) do={
:log info "No-IP: Current IP $currentIP is not equal to previous IP, update needed"
#current IP overrides previous
:set previousIP $currentIP
:local url "https://dynupdate.no-ip.com/nic/update/ ... name=$host"
:log info "No-IP DNS: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP DNS: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}
# end

I have tried this no ip updater behind nat and I am using RouterOS 6.29
But it seems it is not working. It just displays that my dynamic public IP changed but can't update it to noip.

https://drive.google.com/file/d/0B19T49 ... sp=sharing

Djemmy
 
djynny
just joined
Posts: 11
Joined: Thu Jun 30, 2011 9:50 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Wed Dec 09, 2015 6:48 pm

I think I solved it.
#compare IPs
:if ($currentIP not $previousIP) do={
should be
:if ($currentIP != $previousIP) do={

I think it just typo mistake.


Thanks for the script.
 
gbroin
just joined
Posts: 1
Joined: Wed Sep 19, 2018 6:06 pm

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Wed Sep 19, 2018 6:43 pm

It did not work for me, but I think I solved it:

Code: Select all

#Dynamic DNS Update Script for No-IP DNS behind NAT

# Set needed variables
:local username "USER"
:local password "PASS"
:local host "HOST"

# Get Previous IP
:local previousIP [/put [:resolve $host]]

# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]

# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"

#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?myip=$currentIP&hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url user=$username password=$password mode=https keep-result=no
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}

# end
 
alinmear
just joined
Posts: 1
Joined: Fri Feb 19, 2021 9:56 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Thu Jul 22, 2021 11:02 pm

Updated the script. Tested on 7.1beta6:
#Dynamic DNS Update Script for No-IP DNS behind NAT

# Set needed variables
:local username "al1nm3ar"
:local password "!-IcedGuardian86-!"
:local host "pylonlabs.ddns.net"

# Get Previous IP
:local previousIP [/put [:resolve $host]]

# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]

# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"

#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url http-method=post user=$username password=$password mode=https keep-result=no http-data="{\"myip\"=\"$currentIP\"}"
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}

# end
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Sat Jul 24, 2021 11:00 pm

Updated the script. Tested on 7.1beta6:
You need to change your password, since you posted it here, if you not already has done it.
 
karanik
just joined
Posts: 11
Joined: Thu Oct 07, 2021 12:15 am

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Thu Oct 07, 2021 12:17 am

Hello,
Any script for no-ip to work with 6.48 version?
 
User avatar
diamuxin
Member
Member
Posts: 317
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Wed Oct 13, 2021 7:57 pm

Hello,
Any script for no-ip to work with 6.48 version?
Hi, try this:
# No-IP automatic Dynamic DNS update

#--------------- Change Values in this section to match your setup ------------------

# No-IP User account info
:local noipuser "xxxxxxxxxx"
:local noippass "xxxxxxxxxx"

# 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 "xxxxxxxxx.noip.com"

# Change to the name of interface that gets the dynamic IP address, in my case: pppoe-out1
:local inetinterface "pppoe-out1"

#------------------------------------------------------------------------------------
# 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."
}
Regards.
 
hardus
just joined
Posts: 11
Joined: Fri Feb 22, 2013 2:20 pm

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Mon Jan 31, 2022 7:26 am

Hi,

I was originally posting because I cant get it working , but got it working in the end, so heres my solution for those new to Mikrotik:

I first created a Script for the NoIp which worked when I manually run it, but it did not run when I put it in the scheduler:

Heres is what worked:
Caps in the names don't work.

Script Name: noip

Policy: I left it at default all ticked.

Source:
#Dynamic DNS Update Script for No-IP DNS behind NAT

# Set needed variables
:local username "NoIP Username here (Not your email address, your Username"
:local password "NoIP Password Here"
:local host "NoIP Hostname here"

# Get Previous IP
:local previousIP [/put [:resolve $host]]

# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]

# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"

#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url http-method=post user=$username password=$password mode=https keep-result=no http-data="{\"myip\"=\"$currentIP\"}"
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}

# end

Scheduler Settings:

Name: noip
Interval: I initially put it at 0:00:05 for testing to see if it runs, changed it to 00:05:00 after it worked.
Policy: All Defualt Ticked
On Event:
/system script run noip
 
parsaaalm
just joined
Posts: 4
Joined: Sat Jun 15, 2019 11:13 pm

Re: Dynamic DNS Update Script for No-IP DNS behind nat

Sun Jan 28, 2024 3:41 am

Updated the script. Tested on 7.1beta6:
#Dynamic DNS Update Script for No-IP DNS behind NAT

# Set needed variables No-ip
:local username "YOUR USERNAME"
:local password "YOUR PASSWORD"
:local host "YOUR HOSTNAME"

# Get Previous IP
:local previousIP [/put [:resolve $host]]

# Get Current IP using MikroTik IP Cloud feature
/ip cloud force-update
:delay 5
:local currentIP [/ip cloud get public-address]

# Logging IPs
:log info "No-IP: Previous IP = $previousIP"
:log info "No-IP: Current IP = $currentIP"

#compare IPs and update host if needed
:if ($currentIP != $previousIP) do={
:log info "No-IP: Current IP ($currentIP) is not equal to previous IP ($previousIP), update needed"
#current IP overrides previous
:local url "https://dynupdate.no-ip.com/nic/update/?hostname=$host"
:log info "No-IP: Sending update for $host"
#sending infos which are required in the no-ip API via https
/tool fetch url=$url http-method=post user=$username password=$password mode=https keep-result=no http-data="{\"myip\"=\"$currentIP\"}"
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
} else={
:log info "No-IP: update not needed "
}

# end
Worked on Mikrotik OS ver. 7.13.3 behind NAT

Who is online

Users browsing this forum: xrlls and 16 guests