Community discussions

 
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
Networking - R&D Team @ Connectivia Srl
http://www.connectivia.it
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24212
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?
No answer to your question? How to write posts
 
nicholwee
just joined
Posts: 9
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: 9
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: 757
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...
by professionals, for professionals....
Don't forget to give KARMA!!!
 
fuba
just joined
Posts: 2
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

Who is online

Users browsing this forum: No registered users and 6 guests