Community discussions

MikroTik App
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

dynDNS Update Script

Sun Aug 30, 2009 3:01 pm

in order to support dyndns i took some parts from the changeip script and made it work for.

1) add a script called dynDNS:
# Define User Variables
:global ddnsuser "DYNDNSUSER"
:global ddnspass "DYNDNSPASS"
:global ddnshost "DYNDNSHOST"
 
# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
 
:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version] )
 
# Define Local Variables
:local int
 
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}
 
# Grab the current IP address on that interface.
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
 
# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
	 :log info "DynDNS: Sending UPDATE!"
	 :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
	 /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
	 :delay 1
	 :local str [/file find name="DynDNS.$ddnshost"];
	 /file remove $str
	 :global ddnslastip $ddnsip
  }
}
2) Add a scheduler entry to run every minute
/system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDns\r\n"
Thanks to the creator of changeip/everydns-script, i hope it's no problem to use the base or some parts!

hacki
 
opampca
just joined
Posts: 8
Joined: Wed Sep 02, 2009 7:28 am
Location: Montréal Québec Canada

Re: dynDNS Update Script

Wed Sep 02, 2009 7:30 am

Thank you...
This is working great !!!
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Thu Sep 03, 2009 8:36 pm

Hey!

I bought yesterday an RB 750 and I'm trying to setup DynDNS using this script.

I want to ask if the only variables that I have to change is those :

:global ddnsuser "DYNDNSUSER"
:global ddnspass "DYNDNSPASS"
:global ddnshost "DYNDNSHOST"

or I need to change and something else....

I changed those variables but the IP is not changing...

Thanks!
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Fri Sep 04, 2009 1:05 pm

these are the only variables.
what happens if you run the script manually: /system script run dynDNS
have you set the scheduler?
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Fri Sep 04, 2009 3:39 pm

when I executed this

/system script run dynDNS

the script run succesfully and the IP changed!!!

But I have put this script to run on scheduler every 1 minute....
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Fri Sep 04, 2009 4:05 pm

have you added the scheduler job in gui or commandline?

it's important to add the \r\n characters, otherwise the command is not executed
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Fri Sep 04, 2009 6:37 pm

ok!

my scheduler line is :

/system script run dynDNS \r\n

let's see if it's working...
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Sat Sep 05, 2009 11:09 am

It's not working....

Scheduler counting but the IP is not changing...
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Sat Sep 05, 2009 12:22 pm

have you set Policy correctly?
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Sat Sep 05, 2009 4:47 pm

please make "/system scheduler export" and paste it here.
the execute command should be with "" like "/system script run dynDNS\r\n"
you have a whitespace between S and \r, perhaps this is your issue.

you can add the following line on top of the script in order to check wether your script is executed:
:log info "dynDNS script executed"
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Sat Sep 05, 2009 6:28 pm

your scheduler entry should only have "dynDNS" and nothing else ... it's the _name_ of a script to run, not an actual script to run. You do not need \r\n or any of that. I think this changed recently because you used to be able to put scripts in the scheduler directly, now it is just the name of the script you enter.
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Sat Sep 05, 2009 6:33 pm

i set the entry in the gui without \r\n and the script wasn't executed. after adding them it worked so i thought, could be helpful too
 
yarikne
just joined
Posts: 1
Joined: Sun Sep 06, 2009 1:46 am

Re: dynDNS Update Script

Sun Sep 06, 2009 2:06 am

Must I leave " " in variable?
I have error in terminal:
invalid value for argument address

WAN is pppoe to ADSL modem
MikroTik RouterOS 3.22
sorry for my English
Last edited by yarikne on Sun Sep 06, 2009 4:45 pm, edited 1 time in total.
 
mrzero
just joined
Posts: 8
Joined: Sun Sep 06, 2009 9:47 am

Re: dynDNS Update Script

Sun Sep 06, 2009 9:51 am

It says in log file
DynDNS: Sending UPDATE!
fetch: ignoring username and password, only for FTP mode
I'm using Mikrotik 3.13
so anyone know waht's wrong? plz help I need it badly :D
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Sun Sep 06, 2009 12:01 pm

it seems your fetch version won't support usernames in http-mode.
you could try the fetch command with the url tag instead of the address tag.

the address tag was added in version 3.23, so you have to update your box
 
mrzero
just joined
Posts: 8
Joined: Sun Sep 06, 2009 9:47 am

Re: dynDNS Update Script

Sun Sep 06, 2009 6:29 pm

Thank you hacki for replying..
But i open the box terminal and /tool then fetch command and press tab to see available fetch arguments and explore the following:

[admin@mRzErO] /tool> fetch
dst-path host mode password port user address src-path

so what is meant by these arguments; there is an address, user and password :?
but you said it doesn't support address and it said ignoring username and password!!
is it a Bug in MT manual? :)
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Sun Sep 06, 2009 7:34 pm

the http mode won't support user authentification in your version.
your fetch just can auth over ftp
 
mrzero
just joined
Posts: 8
Joined: Sun Sep 06, 2009 9:47 am

Re: dynDNS Update Script

Mon Sep 07, 2009 12:28 am

So, can i install only a one package to do that?
I like the 3.13 version as it is stable version..
and what's version of MT that supports fetch http auth, 3.23 is it?
thanks.. :wink: :wink:
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Mon Sep 07, 2009 12:37 am

sry, not sure for that
 
mrzero
just joined
Posts: 8
Joined: Sun Sep 06, 2009 9:47 am

Re: dynDNS Update Script

Mon Sep 07, 2009 1:00 am

Ok thanks for replying...
I'll try to downgrade the advanced-tools-3.28.npk 8)
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Mon Sep 07, 2009 1:55 am

you cannot use different versions of packages on the same router. you should upgrade
 
mrzero
just joined
Posts: 8
Joined: Sun Sep 06, 2009 9:47 am

Re: dynDNS Update Script

Mon Sep 07, 2009 2:53 am

Yes you are right i tried but it said that the system package must be same as the advanced-tools package..
cheers
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Mon Sep 07, 2009 9:23 am

what I have to select at policy..?

scheduler and script...

My configuration is this :

http://img196.imageshack.us/img196/5932/scriptw.png

http://img401.imageshack.us/img401/8265/scheduler.png
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: dynDNS Update Script

Mon Sep 07, 2009 9:47 am

In scheduler specify only scripts name not a command to run script.
You need at least, read,write,test and ftp policies.
 
johnvam
newbie
Posts: 32
Joined: Thu Sep 03, 2009 8:34 pm

Re: dynDNS Update Script

Mon Sep 07, 2009 10:13 am

OK!

scheduler works perfect!

maybe the problem in on script...

I used the script which is at the top of the thread and I only changed the 3 first variable like this :


:global ddnsuser "xxxxxxx"
:global ddnspass "xxxxxxxx"
:global ddnshost "xxxxxxx.ath.cx"
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Mon Sep 07, 2009 6:50 pm

your scheduler has run the script 1000+ times. Start at the beginning again, what's not working and what are you getting the logs? The script runs fine manually, but not under scheduler? Are you on the latest version?
 
randomseed
newbie
Posts: 31
Joined: Mon Dec 15, 2008 12:52 am

Re: dynDNS Update Script

Thu Sep 10, 2009 4:23 pm

Thanks for the script Hacki. I've inputted my credentials into the ddnsuser, ddnspass and ddnshost string values, but I keep getting the following message:

"[admin@MikroTik] /system script> run script1
interrupted
invalid internal item number"

The only thing I changed was the first three global variables:

:global ddnsuser "xxxx"
:global ddnspass "xxxxxxx"
:global ddnshost "xxxx.dnsalias.net"

Running router OS 3.28 on an RB450.

Tim
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Thu Sep 10, 2009 8:06 pm

Hello,

This is okay, I do not mind. Please, anyone using services other than ChangeIP.com, please be aware that your passwords are being sent across in the internet in clear text. If not using https then it will be easy for someone to detect your credentials.

I love Mikrotik. I have here because of that. I am a Dynamic DNS guy. We provide free services, but I do not feel bad if you choose not to use our services. Of course I know we offer a better service with less hassle, but it's always your choice. : )

Sam
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Sat Sep 12, 2009 9:24 pm

HI,

It's a problem if I delete this from the script?
:if ($ddnsip != $ddnslastip) do={
I have problems updating my ADSL line. First time works, but the others don't. I reboot the router to make the IP change but it doesn't update it in the web. If I delete this line, it works.


The problem now is that every minute my ROS updates or rewrite the IP in dyndns.. Can I have problems doing this?

Thanks,
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Sat Sep 12, 2009 10:09 pm

I'm not sure, but i think dynDNS will ban you for some time if you update so often.

try to input the following commands in your terminal and poste the output

/ip route find dst-address=0.0.0.0/0 active=yes
/ip route get <your ppp Interface> routing-mark
/ip route get <your ppp interface interface
/ip address get [/ip address find interface=<your ppp interface> ] address ]
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Sun Sep 13, 2009 12:40 am

HI,

I don't have ppp in my ROS. ppp is configured in my router. I have a static IP in my ROS eth0 like 192.168.1.x.
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: dynDNS Update Script

Sun Sep 13, 2009 10:38 pm

Just wanted to say nice work on the script! It's been a long time coming, many people have wanted this for some time now.


Thanks again!
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Mon Sep 14, 2009 12:58 am

glad to hear!

to complete it, i added the script to the wiki.
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Mon Sep 14, 2009 1:05 am

HI,

I don't have ppp in my ROS. ppp is configured in my router. I have a static IP in my ROS eth0 like 192.168.1.x.
If this parameter is not specified, the best IP address the server can determine will be used (some proxy configurations pass the IP in a header, and that is detected by the server). If the IP address passed to the system is not properly formed, it will be ignored and the system's best guess will be used.
you could try to remove the ip parameter from the ":local str" variable
remove: &myip=$ddnsip
and try again

if it won't work you could try to do a fetch on http://checkip.dyndns.com/ and compare the content every minute. if the ip address changed, you could parse the ip out of the file and complete the update.
i think this script can help you to work this out: http://wiki.mikrotik.com/wiki/Using_Fet ... ress_Lists
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Mon Sep 14, 2009 11:29 am

Thanks! ; )
 
Lefteris
newbie
Posts: 28
Joined: Mon Jul 27, 2009 1:24 pm

Re: dynDNS Update Script

Fri Sep 18, 2009 4:24 am

After numerous tries the script below seems to work fine under any condition with v3.28. For some reason the original script kept on failing to automatically (manually worked) update DynDNS, specially right after a router reboot.
/system script add name=DynDNS policy=read,test source={
# Define User Variables
:global ddnsuser "user"
:global ddnspass "pass"
:global ddnshost "host"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([:typeof $ddnslastip] = nil) do={ :global ddnslastip "0.0.0.0/0" }

:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version])

# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes] do={
  :if ([:typeof [/ip route get $int routing-mark]] != str) do={
    :global ddnsinterface [/ip route get $int interface]
  }
}

# Grab the current IP address on that interface.
:global ddnsip [/ip address get [/ip address find interface=$ddnsinterface] address]

# Did we get an IP address to compare
:if ([:typeof $ddnsip] = nil) do={
  :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={

  :if ($ddnsip != $ddnslastip) do={

    :log info "DynDNS: Sending IP:$ddnsip UPDATE!"
    /tool fetch keep-result=no url="http://$ddnsuser:$ddnspass@204.13.248.112/nic/update\?hostname=$ddnshost"
    :global ddnslastip $ddnsip

# } else={
#   :log info "DDNS: No update required."
  }

}
}
# End of script
Scheduler:
/system scheduler add name=DynDNS policy=read,test interval=1m on-event=DynDNS
 
User avatar
webasdf
Frequent Visitor
Frequent Visitor
Posts: 87
Joined: Mon Jan 26, 2009 6:37 pm

Re: dynDNS Update Script

Sat Sep 19, 2009 12:37 am

I've made something similar and have been testing for a few weeks...just saw this post and thought I'd share. I haven't been locked out of dyndns yet, so this should be a good script as well. The main difference is that it queries checkip.dyndns.org for the current publicly facing IP address. I also set up a force update once every day at midnight. This prevents the dyndns domain from expiring due to it not being updated enough (which has happened to me in the past). The script has lots of logs and a few puts in it, but these can be safely deleted if desired. The policies on the scripts mentioned above still apply. Make sure those are set properly as well.

The Script "dyndns-update". Set the local variables username, password and hostname:
# Set needed variables
:local username "dyndnsUsername"
:local password "dyndnsPassword"
:local hostname "hostname.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("dyndns-update: username = $username")
:log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")

# 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 "dyndns-update: currentIP = $currentIP"

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("dyndns-update: Dyndns update needed")
    :log info ("dyndns-update: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("dyndns-update: No dyndns update needed")
}
Script "dyndns-force". Intended to update dyndns only once every 24 hrs. If you run this too much, you may get locked out of dyndns.
:global dyndnsForce true
/system script run dyndns-update
Setup the schedulers. Run dyndns-update every 15 minutes and dyndns-force once every 24 hours:
/system scheduler add comment="" disabled=no interval=15m name=dyndns-update on-event=\
    dyndns-update start-date=jan/01/1970 start-time=00:00:00
/system scheduler add comment="" disabled=no interval=1d name=dyndns-force on-event=\
    dyndns-force start-date=jan/01/1970 start-time=02:00:00
 
vdelarenal75
Frequent Visitor
Frequent Visitor
Posts: 70
Joined: Fri May 22, 2009 1:28 am

Re: dynDNS Update Script

Wed Oct 07, 2009 8:10 pm

Thankyou webasfd, you script worked perfectly, thanks for sharing.
I've made something similar and have been testing for a few weeks...just saw this post and thought I'd share. I haven't been locked out of dyndns yet, so this should be a good script as well. The main difference is that it queries checkip.dyndns.org for the current publicly facing IP address. I also set up a force update once every day at midnight. This prevents the dyndns domain from expiring due to it not being updated enough (which has happened to me in the past). The script has lots of logs and a few puts in it, but these can be safely deleted if desired. The policies on the scripts mentioned above still apply. Make sure those are set properly as well.

The Script "dyndns-update". Set the local variables username, password and hostname:
# Set needed variables
:local username "dyndnsUsername"
:local password "dyndnsPassword"
:local hostname "hostname.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("dyndns-update: username = $username")
:log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")

# 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 "dyndns-update: currentIP = $currentIP"

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("dyndns-update: Dyndns update needed")
    :log info ("dyndns-update: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("dyndns-update: No dyndns update needed")
}
Script "dyndns-force". Intended to update dyndns only once every 24 hrs. If you run this too much, you may get locked out of dyndns.
:global dyndnsForce true
/system script run dyndns-update
Setup the schedulers. Run dyndns-update every 15 minutes and dyndns-force once every 24 hours:
/system scheduler add comment="" disabled=no interval=15m name=dyndns-update on-event=\
    dyndns-update start-date=jan/01/1970 start-time=00:00:00
/system scheduler add comment="" disabled=no interval=1d name=dyndns-force on-event=\
    dyndns-force start-date=jan/01/1970 start-time=02:00:00
 
obolyz
just joined
Posts: 2
Joined: Sat Oct 31, 2009 10:37 am

Re: dynDNS Update Script

Sat Oct 31, 2009 7:38 pm

2 hacki:

Script returns:
interrupted
           input does not match any value of value-name
:-(
 
LambdaMaxWELL
just joined
Posts: 9
Joined: Sun Jul 26, 2009 3:52 am

Re: dynDNS Update Script

Thu Dec 10, 2009 9:47 am

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?
Is working fine, thanks!

Question:
How I can modify this script that the current IP will taken out of the dyndns database directly instead of the value stored locally?

Result would be that the update will also be forced in any cases dyndns record was modified by another device etc. for example.

Thanks
Dirk
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Thu Dec 10, 2009 12:23 pm

PreviousIP = [:resolve your.dynhost.tld]
hacki
 
LambdaMaxWELL
just joined
Posts: 9
Joined: Sun Jul 26, 2009 3:52 am

Re: dynDNS Update Script

Thu Dec 10, 2009 12:29 pm

Hello hacki,

thanks for your feedback!
PreviousIP = [:resolve your.dynhost.tld]
hacki
Could I also specify the dedicated nameserver I'd like to query instead of the standard local configured dns server?

Thanks
Dirk
 
hacki
just joined
Topic Author
Posts: 18
Joined: Fri Aug 28, 2009 1:18 am

Re: dynDNS Update Script

Thu Dec 10, 2009 12:59 pm

not sure about that, why do you need this?
 
LambdaMaxWELL
just joined
Posts: 9
Joined: Sun Jul 26, 2009 3:52 am

Re: dynDNS Update Script

Thu Dec 10, 2009 2:09 pm

not sure about that, why do you need this?
I am happy also with the initial version. But if I would take the current IP directly out of the database or if I could directly request the dyndns.org mailserver than I would get the really currently address - device independent.

Otherwise it could be that the local stored address and the content of the dyndns server is different and the script will not make the necessary update. This would not happen normally - that is true.

Dirk
 
LambdaMaxWELL
just joined
Posts: 9
Joined: Sun Jul 26, 2009 3:52 am

Re: dynDNS Update Script

Thu Dec 10, 2009 2:28 pm

not sure about that, why do you need this?
Question:
A command like: "/system nslookup my.domain.tld server ns1.dyndns.org querytype=A >currentIP.txt" is not availiable in RouterOK?

Dirk
 
larryuy
just joined
Posts: 22
Joined: Fri Jun 26, 2009 4:34 pm

Re: dynDNS Update Script

Sat Feb 27, 2010 8:29 pm

Thanks for the script, y have 2 scripts now, one for internet with pppoe (your script) and other for internet with dhcp client or static IP address (default route not asociated with an specific interface).

The diferences:

For PPPoE:
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}
For DHCP or Static IP (senseless for static IP) replace above with this:
:global ddnsinterface "ether1"
And of course:
/system scheduler add name=dynDNS interval=00:01 on-event="/system script run dynDNS\r\n"
Thankyou again.
 
andreico
just joined
Posts: 3
Joined: Fri Nov 20, 2009 10:09 pm

Re: dynDNS Update Script

Mon Mar 15, 2010 3:12 pm

Good afternoon.
I have a problem: tried all options (in my version mikrotik 2.9), did not want to work.
Is it possible to work with this service correctly on my version?
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Mon Mar 15, 2010 3:48 pm

No,

the problem is in fetch tool with the 2.9.x.

3.x solves the script problem with fetch. I think its about validation with fetch in html.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: dynDNS Update Script

Mon Mar 15, 2010 3:50 pm

:shock: v2.9 Doesn't have fetch command.
 
andreico
just joined
Posts: 3
Joined: Fri Nov 20, 2009 10:09 pm

Re: dynDNS Update Script

Wed Mar 17, 2010 1:31 am

Do I correctly indicates the server address? "208.78.71.100"

And if will work, because this team? "dns-update dns-server=208.78.71.100 name=livexxx \
zone=xxxddns.com address=91.215.xx.xx key-name=xxx key=xxx"

But when you enter commands, writes that an incorrect password.

Finally I need a conclusion, if you want more ram head on this version or better to upgrade mikrotik?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: dynDNS Update Script

Thu Mar 18, 2010 2:02 pm

upgrade to newer version, as 2.9 is seriously outdated.
 
MiDoGhOsT
just joined
Posts: 2
Joined: Thu Mar 18, 2010 4:22 am

Re: dynDNS Update Script

Sat Mar 20, 2010 1:08 am

thanks for the script ..
but can you tell me how i change the script to work with opendns ?
 
hkr
just joined
Posts: 12
Joined: Fri Sep 25, 2009 11:16 pm

Re: dynDNS Update Script

Sun Apr 11, 2010 3:02 am

Well, the script works to some extent, but I do not think it sends the IP address to dyndns in the correct way, and it is dyndns itself which determines the IP...

:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]

seems to result in the IP address formatted like: 100.101.102.103/32 and this is the string actually sent to DynDNS. DynDNS does not accept it, however, it will assume that the request has come from the originating IP... For those who have only one active internet connection and active IP, the script will normally work. But in my case it fails as I have multiple IPs.

How can we rewrite the IP address string to contain the address itself only, like 100.101.102.103 and no netmask/etc?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Sun Apr 11, 2010 3:25 am

[admin@MikroTik] > { :local t "1.2.3.4/32"; :put [ :pick $t 0 [ :find $t "/" ] ] }
1.2.3.4
 
downlots
just joined
Posts: 23
Joined: Tue Mar 09, 2010 9:48 pm

Re: dynDNS Update Script

Wed Apr 21, 2010 1:24 am

2 hacki:

Script returns:
interrupted
           input does not match any value of value-name
:-(
Hello guys...and thanks for the script!

I have the same problem. Am using ROS 4.6 on a RB411U.
What can i do?
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Wed Apr 21, 2010 6:22 am

did you specoify the interface with the actual dynamic ip on it? pppoe1 vs ether1 or something?

our system will support x.x.x.x/XX style updates, we just strip out the subnet mask.
 
kolinsb
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: dynDNS Update Script

Sat Apr 24, 2010 10:58 pm

why this script doesn't work:
# Define User Variables
:global ddnsuser "my_username"
:global ddnspass "my_password"
:global ddnshost "my_dyndns_domain"


# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([:typeof $ddnslastip] = nil) do={ :global ddnslastip "0.0.0.0/0" }

# Grab the current IP address on that interface.

:global ddnsip [/ip address get [/ip address find interface=my_pppoe_interface] address]
:global ip [ :pick $ddnsip 0 [ :find $ddnsip "/" ] ]

# Did we get an IP address to compare
:if ([:typeof $ip] = nil) do={
  :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={

  :if ($ip != $ddnslastip) do={

    :log info "DynDNS: Sending IP:$ip UPDATE!"
    /tool fetch keep-result=no url="http://$ddnsuser:$ddnspass@204.13.248.112/nic/update\?hostname=$ddnshost"
    :global ddnslastip $ip

# } else={
#   :log info "DDNS: No update required."
  }

}
}
# End of script
i can't find any error :( i changed some part's of original script....
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Sat Apr 24, 2010 11:08 pm

my_pppoe_interface needs to be in quotes.

i dont know if that fetch command is right. paste the entire thing into terminal with { } surrounding it and see what is highlighted with errors.
 
kolinsb
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: dynDNS Update Script

Sat Apr 24, 2010 11:50 pm

hmmm i don't think so. for test i made some script like this:
:global ddnsip [/ip address get [/ip address find interface=my_pppoe_interface] address]
:global ip [ :pick $ddnsip 0 [ :find $ddnsip "/" ] ]
:log info $ip
and got my public ip as result of this script....
 
andreico
just joined
Posts: 3
Joined: Fri Nov 20, 2009 10:09 pm

Re: dynDNS Update Script

Sun Apr 25, 2010 3:23 am

The Script "dyndns-update". Set the local variables username, password and hostname:
Script "dyndns-force". Intended to update dyndns only once every 24 hrs. If you run this too much, you may get locked out of dyndns.
Setup the schedulers. Run dyndns-update every 15 minutes and dyndns-force once every 24 hours:
Thank you, Your version of Mikrotik 3.30 earned (without problems).
"Installed and running"
Last edited by andreico on Mon Apr 26, 2010 9:18 pm, edited 1 time in total.
 
kolinsb
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: dynDNS Update Script

Sun Apr 25, 2010 10:05 pm

i tryed all theese scripts, but no one doesn't working :( :( :(
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: dynDNS Update Script

Mon Apr 26, 2010 10:56 am

what version of RotuerOS you are using?
 
kolinsb
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: dynDNS Update Script

Tue Apr 27, 2010 9:56 pm

i using v4.6 on Pentium3 machine.
 
User avatar
THG
Member
Member
Posts: 472
Joined: Thu Oct 15, 2009 1:05 am

Re: dynDNS Update Script

Tue Apr 27, 2010 9:57 pm

2 hacki:

Script returns:
interrupted
           input does not match any value of value-name
:-(
Same problem with RouterOS Version 4.7.


Edit: Working Script.
# Set needed variables
:local username "YourUsername"
:local password "YourPassword"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info 
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}

 
rege245
just joined
Posts: 1
Joined: Sat May 08, 2010 9:00 am

Re: dynDNS Update Script

Sat May 08, 2010 1:17 pm

Hello, i test this script, but i've got error BADAUTH

[admin@Router] > /system script run ddns
status: finished

status: finished

Dyndns Update Result: badauth
echo: script,info dyndns-update: username = xxx@xxx.xx
echo: script,info dyndns-update: password = xxxxxx
echo: script,info dyndns-update: hostname = xxxx.homeip.net
echo: script,info dyndns-update: previousIP =
echo: info fetch: file "dyndns.checkip.html" created
echo: script,info dyndns-update: currentIP = 95.101.117.110
echo: info fetch: file "dyndns.txt" created
[admin@Router] >
echo: script,info dyndns-update: Dyndns update needed
echo: script,info dyndns-update: Dyndns Update Result: badauth

IP address is resolved corectly, but update dont work....


please help :(


EDIT: I found error, i used email address as login...
 
kolinsb
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Sat Jun 30, 2007 7:22 pm

Re: dynDNS Update Script

Wed Jun 30, 2010 8:53 am

Must I leave " " in variable?
I have error in terminal:
invalid value for argument address

WAN is pppoe to ADSL modem
MikroTik RouterOS 3.22
sorry for my English
hope so, that my answar will help to someone. i had exactly same problem, and a problem was in default routes in Mikrotik. All my default routes had some routing marks, and i made one without routing mark, and then everything was fine. in this case, Mikrotik was without internet access (i couldn't ping any address or host on internet)
 
takisg
just joined
Posts: 1
Joined: Fri Jul 02, 2010 12:21 pm

Re: dynDNS Update Script

Fri Jul 02, 2010 12:37 pm

This script I bielieve that writes two files to the local file system.(dyndns.checkip.html, dyndns.txt)
I use a compact flash and if the script run every minute is it right ?

Is it good for the lifetime of the compact flash....
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Mon Jul 05, 2010 10:20 pm

The script working before in 4.3, doesn't work after update to 4.6..
 
TerAnYu
newbie
Posts: 28
Joined: Sun Jun 20, 2010 1:46 pm
Location: Russia, Novosibirsk

Re: dynDNS Update Script

Sat Aug 07, 2010 10:21 pm

Working script RouterOS 4.10
# Set needed variables
:local username "Login_dyndns.com"
:local password "Password_dyndns.com"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname  = "MikroTik" ) do= {
:set hostname "site1.dyndns.org,site2.homeip.net,site3.dyndns.org,etc.dyndns.org"
}


:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
#  but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
 
taduikis
Member
Member
Posts: 436
Joined: Sat Jul 07, 2007 12:09 pm

Re: dynDNS Update Script

Wed Aug 25, 2010 11:00 pm

What if my IP address doesn't change very often? I mean, it's called dynamic by my ISP, but as far as I'm concerned it doesn't change for a few months or so. And since free DynDNS service requires that you update your IP at least once a month, this script could easily get it expired. It would be nice to modify this script, so the IP gets updated for example every 20 script runs (depending on execution intervals) to avoid expiration.

One solution to this problem could be another script (scheduled to run once a week) that updates IP every time it's executed.

Just a thought though.
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Thu Aug 26, 2010 10:15 am

Hi taduikis!

You can run this script every 10 days, for example or twice a week:
# Set needed variables
:local username "Login_dyndns.com"
:local password "Password_dyndns.com"
:local hostname "siteX.dyndns.org"



:global dyndnsForce
:global previousIP

:set dyndnsForce true

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"


# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html

    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update forced")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
 
fatslim
newbie
Posts: 30
Joined: Mon Dec 01, 2008 1:21 pm
Location: Lithuania, Kaunas
Contact:

Re: dynDNS Update Script

Mon Sep 13, 2010 7:39 pm

Hello everyone. I am using this script:
# Set needed variables
:local username "YourUsername"
:local password "YourPassword"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
#  but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
what should i enter here
:local hostname "nohostset"
and here
:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}
when i ran this script with these values i got such result:
Image

should i change anything?
 
larryuy
just joined
Posts: 22
Joined: Fri Jun 26, 2009 4:34 pm

Re: dynDNS Update Script

Mon Sep 13, 2010 9:17 pm

Fatslim, you can use this commands:
:local hostname [/system identity get name]
and use your entirely domain name as your router identity.

Other option, upload the files: user.txt, password.txt and host.txt with the specific information for each router and use this script:
# Set needed variables
:global username [/file get user.txt contents]
:global password [/file get password.txt contents]
:global hostname [/file get host.txt contents]

:global dyndnsForce
:global previousIP

:set previousIP [:resolve domain-name=$hostname]

# print some debug info
:log info ("dyndns-update: username = $username")
:log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")

# 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"
:global 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 "dyndns-update: currentIP = $currentIP"

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"

    :local result [/file get dyndns.txt contents]
    :log info ("dyndns-update: Dyndns update needed")
    :log info ("dyndns-update: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)

} else={
    :log info ("dyndns-update: No dyndns update needed")
}





Best regards.
 
mikiplus
just joined
Posts: 10
Joined: Sun Oct 03, 2010 12:08 pm

Re: dynDNS Update Script

Sun Oct 03, 2010 12:14 pm

I have RB miniRouter (mipsle) v3.30.

When I execute:

/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"

The console returns:

invalid value for argument address

What is the problem?
 
User avatar
Ibersystems
Forum Guru
Forum Guru
Posts: 1686
Joined: Wed Apr 12, 2006 12:29 am
Location: Cabrils, Barcelona - Spain
Contact:

Re: dynDNS Update Script

Mon Oct 04, 2010 12:33 pm

hello,

your minirouter has DNS configured?
/ip dns
set allow-remote-requests=no cache-max-ttl=1w cache-size=2048KiB \
    max-udp-packet-size=512 servers=62.81.0.35,80.58.0.33
 
mikiplus
just joined
Posts: 10
Joined: Sun Oct 03, 2010 12:08 pm

Re: dynDNS Update Script

Mon Oct 04, 2010 12:49 pm

ok, the dns has not configured. Thank you!
hello,

your minirouter has DNS configured?
/ip dns
set allow-remote-requests=no cache-max-ttl=1w cache-size=2048KiB \
    max-udp-packet-size=512 servers=62.81.0.35,80.58.0.33
 
SolarW
newbie
Posts: 40
Joined: Mon Nov 29, 2010 3:37 am

Re: dynDNS Update Script

Tue Nov 30, 2010 10:07 pm

Hi.

I have several routers RB750.
Each of them is connected to the Internet via two channels.
One of the main, second backup.
Channels toggle script checks the availability of the Internet through the main channel.
How do I decide on what ip-address of the router is accessible from the Internet?
This code
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}
not work on 4.13.
Metod with checkip.dyndns.org uses flash memory on each run.
If running script every 1 min (ok, every 5 min) - how quickly corrupt flash memory?
I would like to still use the first method - to determine the address of the interface through which assigned a default gateway (route 0.0.0.0.0)
 
fquiles
just joined
Posts: 1
Joined: Wed Jan 26, 2011 9:33 pm

Re: dynDNS Update Script

Wed Jan 26, 2011 9:58 pm

Hi this script stays on Update IP needed SENDING UPDATE!
after that nothing happens, im running on V4.5 a PPPoE connection.

Thanks


:local ddnsuser "host"
:local ddnspass "pass"
:local theinterface "PPPoE"
:local ddnshost "host.dyndns.org"
:local ipddns [:resolve $ddnshost];
:local ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynDNS: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}

:if ($ipddns != $ipfresh) do={
:log info ("DynDNS: IP-DynDNS = $ipddns")
:log info ("DynDNS: IP-Fresh = $ipfresh")
:log info "DynDNS: Update IP needed, Sending UPDATE...!"
:local str "/nic/update?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
:delay 1
:local str [/file find name="DynDNS.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynDNS: IP updated to $ipfresh!"
} else={
:log info "DynDNS: dont need changes";
}
}
 
madrian
just joined
Posts: 3
Joined: Fri Feb 11, 2011 3:26 am

Re: dynDNS Update Script

Fri Feb 11, 2011 3:28 am

Hi
b]/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"[/b]

bad-argument name src-path (line 1 column 52)

What can be the problem?
 
jadu
Frequent Visitor
Frequent Visitor
Posts: 86
Joined: Sat Feb 05, 2011 9:22 am
Location: Bucharest - Constanta

Re: dynDNS Update Script

Mon Mar 14, 2011 1:58 pm

Hi
b]/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"[/b]

bad-argument name src-path (line 1 column 52)

What can be the problem?
what router OS version do you use?
 
Yukado
newbie
Posts: 27
Joined: Tue Apr 20, 2010 10:37 pm

Re: dynDNS Update Script

Sat Mar 26, 2011 3:27 am

Hi,

I am using the Dyndns script and this works fine, but I have a problem. I have added this script to the schedule, but It doesn't work.

I don't know why it does not work. If you can give and answer.

Thanks in advance.
 
larryuy
just joined
Posts: 22
Joined: Fri Jun 26, 2009 4:34 pm

Re: dynDNS Update Script

Sat Mar 26, 2011 6:36 pm

Yukado, please put exactly the script you are using.
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: dynDNS Update Script

Sat Mar 26, 2011 7:19 pm

I too would like a version that works with OpenDNS. Anyone tried this yet?
 
jadu
Frequent Visitor
Frequent Visitor
Posts: 86
Joined: Sat Feb 05, 2011 9:22 am
Location: Bucharest - Constanta

Re: dynDNS Update Script

Tue Mar 29, 2011 5:29 pm

Hi,

I am using the Dyndns script and this works fine, but I have a problem. I have added this script to the schedule, but It doesn't work.

I don't know why it does not work. If you can give and answer.

Thanks in advance.
You should type into On Event: "/system script run "script_name"
 
carboncopy
just joined
Posts: 3
Joined: Thu Dec 23, 2010 11:31 am
Location: Kuala Lumpur

Re: dynDNS Update Script

Wed Mar 30, 2011 6:32 pm

How to make the script update 2 pppoe interface?
Same user. 2 host name, 2 pppoe.
 
jadu
Frequent Visitor
Frequent Visitor
Posts: 86
Joined: Sat Feb 05, 2011 9:22 am
Location: Bucharest - Constanta

Re: dynDNS Update Script

Mon Apr 04, 2011 1:11 pm

How to make the script update 2 pppoe interface?
Same user. 2 host name, 2 pppoe.
I have the same situation like you.
You should make 2 scripts and add them to the scheduler.
In each script you have the pppoe1 connection and respectively the pppoe2 connection.
 
arpadffy
Frequent Visitor
Frequent Visitor
Posts: 50
Joined: Mon Jan 17, 2011 1:52 am
Location: Stockholm, Sweden
Contact:

Re: dynDNS Update Script

Fri Apr 22, 2011 7:18 pm

Hello,

I have the same problem... I would like to update the pppoe-out1 interface, but this is not the default gateway.

I have solved easily how to fetch the right IP with:
:global ddnsinterface "pppoe-out1"

if ([:typeof $ddnsinterface] = nil) do={
# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
  :foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes] do={
    :if ([:typeof [/ip route get $int routing-mark]] != str) do={
      :global ddnsinterface [/ip route get $int interface]
    }
  }
}


But the http request goes through the default gateway therefore the dyndns.org takes that IP and not the pppoe-out1 interface.

Is there any way to route mark this request?

Thank you in advance.

Regards,
Z
 
scottedge
just joined
Posts: 4
Joined: Tue Jun 28, 2011 9:32 am

Re: dynDNS Update Script

Tue Jun 28, 2011 8:26 pm

modified version of script on the forum working in 5.x
# Set needed variables
:local username "USERNAME"
:local password "PASSWORD"
:local hostname "HOSTNAME"

:global dyndnsForce
:global previousIP 

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={

:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
 
heviejob
Member Candidate
Member Candidate
Posts: 171
Joined: Mon Nov 30, 2009 4:54 pm

Re: dynDNS Update Script

Sat Aug 13, 2011 8:00 am

I have the script running successfully with one Internet facing interface.
I added a 2nd Internet link now the script picks the IP address second
one instead of the first one. I checked in the script there is no where
to specify the interface to check so how do i add it?

# Set needed variables
:local username "xxxxxx"
:local password "xxxxxx"
:local hostname "xxxx.xxx.com"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
#  but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
 
User avatar
elgo
Member Candidate
Member Candidate
Posts: 151
Joined: Sat Apr 02, 2011 2:34 am
Location: France

Re: dynDNS Update Script

Sun Aug 14, 2011 6:05 pm

Look on this forum or wiki, there are different versions of this script that get their IP adress by different means (static interface name specification, etc).
 
Jeroen1000
Member Candidate
Member Candidate
Posts: 202
Joined: Fri Feb 18, 2011 2:05 pm

Re: dynDNS Update Script

Wed Dec 07, 2011 9:58 pm

Is it possible to avoid disk writes if no update is required?

So avoiding this part:
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]
thanks a lot,
Jeroen
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: dynDNS Update Script

Wed Dec 07, 2011 10:08 pm

Sure, if the public IP is configured right on the router you can just check the interface IP directly. The fetch only happens in case you're behind NAT and need to update a public IP you can't access locally directly.
 
Jeroen1000
Member Candidate
Member Candidate
Posts: 202
Joined: Fri Feb 18, 2011 2:05 pm

Re: dynDNS Update Script

Wed Dec 07, 2011 10:55 pm

I found this snippet to get the IP however, it makes the script halt although the console does not indicate an error.
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}
A log statement (see below) before this snippet works, a log statement just after does not.
:log info "UpdateDynDNS TEST TEST TEST: currentIP = TEST A"
I'm going to try and mend it, but why does it halt the script when there are no errors? I'm not a profiecient programmer I'm afraid:)
 
Jeroen1000
Member Candidate
Member Candidate
Posts: 202
Joined: Fri Feb 18, 2011 2:05 pm

Re: dynDNS Update Script

Fri Dec 09, 2011 12:02 am

I'm happy to report I've got a working script now (source code below). However, When forcing an update DynDns reports "nochg 84.194.xxx.xxx"

And thus it does not update the "Last Updated" timer, which may cause the account to expire. Anyone found a way around this?


# Set needed variables
:local username "YOUR_USERNAME"
:local password "YOUR_PASSWORD"
:local hostname "YOUR_HOSTNAME"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "yourdomain1.dyndns.org"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "yourdomain2.dyndns.org"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "yourdomain3.dyndns.org"
}

:global dyndnsForce
:global previousIP

# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
#:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# CAUTION: YOU NEED TO SELECT THE INTERFACE WHICH HAS YOUR PUBLIC IP. Here this is interface number=1

:local network [/ip address get number=1 address]
#:log info (" network is $network")

:local length [:len $network]
#:log info ("length is $length")
:local currentIP [:pick $network 0 ($length-3)]
:log info ("UpdateDynDNS: fetched IP address  is $currentIP")

# Remove the # on next line to force an update every single time - useful for debugging,
#  but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
       src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
 
morseman21
just joined
Posts: 5
Joined: Sat Apr 30, 2011 4:52 pm
Location: Bucharest, Romania

Re: dynDNS Update Script

Thu Dec 15, 2011 3:27 pm

I currently have two RB450G devices. One will be used as a SSTP server and the other as a SSTP client.

I have used a script from a mikrotik wiki page using DDNS service from DYNDNS.org:
# Set needed variables
:local username "username"
:local password "password"
:local hostname "blahblahblah.dyndns.org"

:global dyndnsForce
:global previousIP 

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :set dyndnsForce false
   :set previousIP $currentIP
   :log info "$currentIP or $previousIP"
   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
      dst-path="/dyndns.txt"
   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
   :put ("Dyndns Update Result: ".$result)
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
The script works great for my Dynamic IP SSTP server. However my Static SSTP client resolves the server Host name to IP address when applied and it does not update when the Dynamic IP of my SSTP server changes. I need to know how I can update the IP address of my Dynamic IP SSTP server into the address field for my SSTP client settings.

Is there a Guru out there that can help me. I can't imagine I'm the first person looking for an answer to this question.

Thank you
 
Cris@usai.net
newbie
Posts: 42
Joined: Fri Jun 17, 2005 8:25 pm

dynDNS Update Script

Fri Dec 16, 2011 11:20 pm

I have a interesting situation.

have one router/Mikrotik with multiple Dynamic connections.
1 DSL and one 1 Wireless.
one is set as primary and one is set as secondary.
Uses the dyndns script to update the dns for the router.

I would like to test to confirm that both interfaces are actually connected.
I would like to see about getting the dynamic dns script to test via a forced interface opposed to the default routed interfaces.

currently the line in the script shows as
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"

is their a way to tell the fetch command to use a particular interface?
such as
/tool fetch interface= eth1 mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"

any Ideas?
 
User avatar
elgo
Member Candidate
Member Candidate
Posts: 151
Joined: Sat Apr 02, 2011 2:34 am
Location: France

Re: dynDNS Update Script

Mon Dec 19, 2011 12:18 pm

@Cris@usai.net:
Ugly workaround: add a temporary specific route to dyndns.org? :)
 
janisbvp
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Thu Jul 15, 2010 10:33 am

Re: dynDNS Update Script

Wed Dec 21, 2011 12:52 pm

I would propose a clean workaround in one of 2 ways:

1. Create an update daemon for ROS (sources are out there - use ready made inadyn or whatever) and stop this script menace for once.
2. For security reasons, create a dns service for MT clients, so we don't use dyndns, although, I think dyndns is secure enough.

An, yes, Normis, I know - not planned, no time for this, no real neccesity, but still - please, pretty please.
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Wed Dec 21, 2011 7:44 pm

I am working on a udp ddns update client for routeros that hopefully will make everyones lives easier. Will just be tied to the MAC / serial of the units and calls home with a lightweight udp packet. You then come to our site (ChangeIP.com) to tell us which units are yours and then you can tie them all together in your account.

Sam
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Thu Dec 22, 2011 10:52 am

routed MNDP (CDP)?.. O_o
 
shulsen
just joined
Posts: 2
Joined: Thu Dec 22, 2011 12:37 am

Re: dynDNS Update Script

Thu Jan 05, 2012 1:01 am

I have been trouble shooting a problem with a group of routers that use the script. When the script is run, it will log that no update is needed even though I can see that the resolved IP of the *dyndns.org domain is not the actual IP of the device.

I can manually force the update and it works just fine. Which means there is something going on with the if statement that decides if the update happens.

After looking at the script I have noticed that the script never checks to see if the update command successfully completes, but the script still changes the value of the previous IP variable. Meaning, the variable the script uses to compare the current IP with is getting updated even if the actual dyndns update isn't happening.

So if the below line of code ever does not get processed by the dyndns.org servers successfully, the scripts won't know this, but wills till proceed to alter the previous IP variable. So the next time the script is run, if will see the newly updated previous IP variable and compare it with the contents of the current IP variable. But the IP address in the dyndns entry will still be the previous IP before the last time the script ran.
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
      dst-path="/dyndns.txt"
I believe parsing the html page that is returned after executing this and testing to see if the word "good" appears and then containing the update of the previous IP variable in an if statement that checks if the result contains "good" should resolve this issue.

I have added this below the line above to help prevent this from happening.
    # parse the results of update
    :local resultLen [:len $result]
    :local startLoc [:find $result "Go" -1]
    :local endLoc [:find $result "od" -1]
    :local resultParse [:pick $result $startLoc $endLoc]
    :log info ("Update was successful: ".$resultParse)
    :if (($resultParse = "Good") do ={
	     :log info ("Update was successful: ".$resultParse)
        :set previousIP $currentIP
    } else={
        :log info ("UpdateDynDNS: Update failed!")
    }
This block should catch to see if Good appears in the returned text, and if it does it will allow the previousIP variable to be updated. If it does not appear, it will not happen, but the next time the script is called it should trigger the update again.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: dynDNS Update Script

Thu Jan 05, 2012 1:14 pm

routed MNDP (CDP)?.. O_o
it will be external tool, not inside the RouterOS.
 
dimdjd
just joined
Posts: 3
Joined: Wed Jan 11, 2012 5:11 pm

Re: dynDNS Update Script

Wed Jan 11, 2012 5:42 pm

Offer my version of the dynDNS Update script:
Script check the current IP address in DNS resolve for hostname, and if needed it change in dynDNS profile
# Set needed variables
:local username "YourUserName"
:local password "YourPassword"
:local hostname "YourHostName"

:global dyndnsForce

# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
#:log info ("UpdateDynDNS: hostname = $hostname")

# 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 "UpdateDynDNS: currentIP = $currentIP"

#get IP from DynDNS for our hostname
:local resolvedIP [:resolve $hostname]
:log info ("UpdateDynDNS: resolved IP =$resolvedIP")

# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $resolvedIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
Schedule it every 1 minute. It works for me perfectly on MikroTik RouterOS v5.xx ;)
 
User avatar
elgo
Member Candidate
Member Candidate
Posts: 151
Joined: Sat Apr 02, 2011 2:34 am
Location: France

Re: dynDNS Update Script

Thu Jan 12, 2012 11:58 am

dimdjd: so every minute you have data written on your flash. Bad. Better scripts exist for the same purpose.
 
dimdjd
just joined
Posts: 3
Joined: Wed Jan 11, 2012 5:11 pm

Re: dynDNS Update Script

Thu Jan 12, 2012 7:30 pm

elgo: fair comment!
So, here is my version without the continual disk operations
# Set needed variables
:local username "YourUserName"
:local password "YourPassword"
:local hostname "YourHostName"
:global ddnsinterface "YourInternetInterfaceWithDynamicIP"
:global ddnsip ""

:global dyndnsForce
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];
:log info ("UpdateDynDNS: currentIP = $ddnsip")

#get IP from DynDNS for my hostname
:local resolvedIP [:resolve $hostname]
:log info ("UpdateDynDNS: resolved IP =$resolvedIP")

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($ddnsip != $resolvedIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$ddnsip" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
Thanks, it really will save lives of MLC Flash chips, used in routerboard™ devices! :)
Last edited by dimdjd on Thu Jan 26, 2012 12:40 pm, edited 1 time in total.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Fri Jan 13, 2012 11:53 am

routed MNDP (CDP)?.. O_o
it will be external tool, not inside the RouterOS.
where will it run?.. on dedicated server, not on the router itself?..
 
User avatar
nullx8
just joined
Posts: 13
Joined: Wed Jan 18, 2012 12:28 am
Location: Bangkok, Thailand
Contact:

Re: dynDNS Update Script

Fri Jan 20, 2012 12:36 am

elgo: fair comment!
So, here is my version without the continual disk operations
#get IP from DynDNS for my hostname
:local resolvedIP [:resolve $hostname]
:log info ("UpdateDynDNS: resolved IP =$resolvedIP")

...
better to use one of the dyndns nameservers to resolve the name
avoiding DNS cache

like this
:local resolvedIP [:resolve domain-name=$hostname server=204.13.248.75]
 
cosmin
just joined
Posts: 1
Joined: Thu Feb 02, 2012 7:10 pm

Re: dynDNS Update Script

Sat Feb 04, 2012 11:17 am

I have a 450G version 5.12. Tried all scripts and none is working! Please advise.
Nevermind, everything's peaches :)
 
User avatar
Question42
just joined
Posts: 15
Joined: Fri Nov 12, 2010 11:05 pm

Re: dynDNS Update Script

Sun Feb 05, 2012 11:58 am

Note that performing a DNS query to see if the hostname needs updated is in breach of Dyn's policies, as is using checkip.dyndns.org every minute:
Unacceptable Client Behavior

* Send requests to or access anything other than /nic/update at the host members.dyndns.org.
* Reverse engineer web requests to our website to create or delete hostnames.
* Hardcode the IP address of any of the Dyn servers.
* Attempt to update after receiving the notfqdn, abuse, nohost, badagent, badauth, badsys return codes or repeated nochg return codes without user intervention.
* Perform DNS updates to determine whether the client IP needs to be updated.
* Access our web-based IP detection script (http://checkip.dyndns.com/) more than once every 10 minutes
Emphasis mine. Doing that may result in all RouterOS devices being blocked from submitting updates (Dyn do that for badly behaved user agents) and possibly even they'll stop reporting a valid value at checkip.dyndns.org.
 
biland
just joined
Posts: 21
Joined: Thu Jan 26, 2012 1:01 pm
Location: tuxtepec, mexico
Contact:

Re: dynDNS Update Script

Sun Feb 26, 2012 7:22 am

anyway what other ddns server can you use since dyndns is not free anymore are there scripts made for other servers
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: dynDNS Update Script

Mon Feb 27, 2012 12:57 am

changeip.com - we are the only ones that have ssl updates in routeros, and actually support and use routeros. everyone else will just ban you for too many updates ; )
 
Beone
Trainer
Trainer
Posts: 250
Joined: Fri Feb 11, 2011 1:11 pm

Re: dynDNS Update Script

Tue Mar 06, 2012 3:53 pm

Note that performing a DNS query to see if the hostname needs updated is in breach of Dyn's policies, as is using checkip.dyndns.org every minute:
Unacceptable Client Behavior

* Send requests to or access anything other than /nic/update at the host members.dyndns.org.
* Reverse engineer web requests to our website to create or delete hostnames.
* Hardcode the IP address of any of the Dyn servers.
* Attempt to update after receiving the notfqdn, abuse, nohost, badagent, badauth, badsys return codes or repeated nochg return codes without user intervention.
* Perform DNS updates to determine whether the client IP needs to be updated.
* Access our web-based IP detection script (http://checkip.dyndns.com/) more than once every 10 minutes
Emphasis mine. Doing that may result in all RouterOS devices being blocked from submitting updates (Dyn do that for badly behaved user agents) and possibly even they'll stop reporting a valid value at checkip.dyndns.org.

This is indeed the problem with that script.
max connect limit reached. You have to get rid of checking checkip.dyndns.org every minute or you will keep having problems.
 
janisbvp
Frequent Visitor
Frequent Visitor
Posts: 76
Joined: Thu Jul 15, 2010 10:33 am

Re: dynDNS Update Script

Fri Mar 09, 2012 9:46 am

http://www.hark.com/clips/fjppvkfnzr-i-been-saying-it
I think it shares my thoughts on this matter.
Just a single daemon, compiled from a ready-made source and integrated in ROs would have saved us from this thread.
 
gsloop
Member Candidate
Member Candidate
Posts: 213
Joined: Wed Jan 04, 2012 11:34 pm
Contact:

Re: dynDNS Update Script

Mon Mar 12, 2012 8:25 pm

I've rewritten [well, actually mostly written from scratch] a dyndns script.

The post is here: http://forum.mikrotik.com/viewtopic.php ... 91#p306491

I have a few changes I'm working in still, but this should work just fine.
It does NOT do double-NAT, but it does stay within the TOS at DynDNS.
[i.e. It DOES keep IP state between reboots, thus preventing a "nochg" update for the first run after a reboot.]
You can run it as often as you like, even once a second.
It only writes to flash when an IP change occurs. The writes are also very small, so flash write exhaustion should be a very minimal issue, if one at all.

The code is extensively commented, so you should very easily find your way around.

I'm planning on adding it to the Wiki, but this is where things are for now.

Oh, final things:
It's written and tested on 5.12 only. I'd assume it should work on other releases, but I'm not sure which.
It was also written and tested on a RB-450G - again it should work on most anything, but I've spent no time validating on any other RB's.

Finally, if you use it and do so successfully, could you please contribute back by letting me know:
1) That it worked successfully.
2) What ROS hardware.
3) What ROS software version.
4) If you make changes, could you let me know what for, and if possible submit the code back.

Thanks,
Greg
 
kk2628
just joined
Posts: 8
Joined: Sun Apr 29, 2012 12:23 pm

Re: dynDNS Update Script

Sat May 05, 2012 2:16 pm

Hi,

When I change the firewall filter to drop all input on my gateway interface, I am not able to run this command successfully
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"

I got the error "while resolving ip: could not get answer from dns server"

I have tried to accept TCP and UDP port 53 but still not working. And what really puzzle me is I am actually at the internal LAN behind the firewall, why this still happen ? Mikrotic really gave a lot of surprises to me :? In the past, I can just configure what I want with simple few clicks, but now, to do a simple thing like this will take me hours if not days. :(

Any advise which port I should open ? Or what did I do wrong ?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: dynDNS Update Script

Mon May 07, 2012 1:02 pm

if you drop everything on input, router cannot receive anything from the internet. first, accept established and related conections - that will allow all router-initiated sessions

nothing changed from the previous century
 
estanenmi
just joined
Posts: 1
Joined: Thu Jun 21, 2012 7:51 pm

Re: dynDNS Update Script

Thu Jun 21, 2012 8:32 pm

# Set needed variables
:local username "YourUserName"
:local password "YourPassword"
:local hostname "YourHostName"
:global ddnsinterface "YourInternetInterfaceWithDynamicIP"
:global ddnsip ""

:global dyndnsForce
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];
:log info ("UpdateDynDNS: currentIP = $ddnsip")

#get IP from DynDNS for my hostname
:local resolvedIP [:resolve $hostname]
:log info ("UpdateDynDNS: resolved IP =$resolvedIP")

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($ddnsip != $resolvedIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$ddnsip" dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}

i use this script in my router 751... i want use external ip this script check my local ip how i fix??
 
User avatar
explorer84
just joined
Posts: 5
Joined: Sun Dec 04, 2011 11:32 pm
Location: Odessa, Ukraine

Re: dynDNS Update Script

Mon Oct 15, 2012 9:38 pm

Works on ROS v5.20
#To RUN script USE ----->>   /system script run dynDns
#
:local ddnsuser "username"
#
# CHANGE PASSWORD, hostname, username and interface to match yours!
#
:local ddnspass "pass"
:local theinterface "eth1"  
:local ddnshost "yourhost"
:local ipddns [:resolve $ddnshost];
:local ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("DynDNS: No ip address on $theinterface .")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
    :set ipfresh [:pick $ipfresh 0 $i];
      } 
}
 
:if ($ipddns != $ipfresh) do={
    :log info ("DynDNS: IP-DynDNS = $ipddns")
    :log info ("DynDNS: IP-Fresh = $ipfresh")
   :log info "DynDNS: Update IP needed, Sending UPDATE...!"
   :local str "/nic/update?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
   /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
         password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ipddns $ipfresh
  :log info "DynDNS: IP updated to $ipfresh!"
    } else={
     :log info "DynDNS: dont need changes";
    }
}
    }
} need changes";
    }
}members.dyndns.org src-path=$str mode=http user=$ddnsuser \
        password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip
  }
}
 
ABeepMike
Frequent Visitor
Frequent Visitor
Posts: 51
Joined: Tue Nov 10, 2009 10:37 pm

Re: dynDNS Update Script

Tue Oct 30, 2012 12:53 am

Hi,

I am using Greg Sowell's DYNDns scripts for the vpn tunnels I am constructing.

http://gregsowell.com/?p=1523

and

http://wiki.mikrotik.com/wiki/Dynamic_D ... behind_NAT

the "behind nat" script works for me on 5.14 , but it has caveats:

uses DNSOMATIC :(



I would like to use a straight to DYNDNS script to :

A : update the Tik's wan IP to automatic on change of IP or a manually via run or a removal of if then else set of commands....a force update , if you will .



B: straight to Dyndns script for the resolving of local and remote host ips for policy and peer in vpn tunnels , with the router associated dst and src path updated, just the Sowell script minus the DNSOMATIC stuff.

The Sowell method works, but I pay for DYNDNS , and really want to take out the middle man in this setup.
 
mixa1977
just joined
Posts: 1
Joined: Thu Nov 08, 2012 12:19 pm

Re: dynDNS Update Script

Thu Nov 08, 2012 12:28 pm

Good script!
But I had a problem. Once "dyndns.org" refused to update. So I turned on the test result updates. The changes are "# UP!!!".
I am a novice.


# Set needed variables
:local username "YOURUSER"
:local password "YOURPASWORD"
:local hostname "YOURHOSTNAME.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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"
:delay 1
: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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
#:set previousIP $currentIP
:log info "$currentIP or $previousIP"

/file remove [find name="dyndns.txt"]

/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)

:local StatusUp [:pick $result 0 4]
:if (($StatusUp = "good") || ($StatusUp="noch")) do={
:set previousIP $currentIP
} else={
}


:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
 
ABeepMike
Frequent Visitor
Frequent Visitor
Posts: 51
Joined: Tue Nov 10, 2009 10:37 pm

Re: dynDNS Update Script

Thu Nov 22, 2012 4:20 am

Using bits of script from this thread and Greg Sowell's tutorial and examples, I have a Tik with a DynDNS WAN and IPsec tunnels with DynDNs entries for both SA-Src and SA-Dst in each tunnel pointed back at the TIK


In the Tik scripts here,,,there is an IF , Then, Else portion for the Tik's WAN ....if no updated is needed after resolve, no action taken...and I use that for this Tik, even though it probably wont ever get another address....but just in case, its there.

I need close to the same thing for this code....

I am resolving both the local and the remote dyndns for each tunnel via a scheduled script every ten minutes and updating the policy and peer for each tunnel...in order.

Works great...but, every time it resolves, even if it gets the same result, it updates the peer and policy to every tunnel, resulting in new SA's i.e. tunnel setup. Every ten minutes.

I need to resolve every ten minutes because I am checking for an address change on failover at those tunnel ends.

So, can a fetch..check a variable, change if necessary script , if not leave alone script be written for each tunnel's local and remote site dyndns?

I think I am close, but a push in the right direction would be appreciated.

I am resolving the local site with a different variable for the same ip address for each tunnel ....it may not be needed, but it worked. It populates the peers and policies perfectly for all 20 tunnnels.

I would just like to change the tunnel ip addresses only when needed by a change after resolve.



add name="Tunnel 0" policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    source=":global LocalSite [:resolve x1.dyndns.org]\r\
    \n:global RemoteSite0 [:resolve y1.dyndns.org]\r\
    \n/ip ipsec policy set 0 sa-dst-address=\$RemoteSite0 sa-src-address=\$Loc\
    alSite \r\
    \n/ip ipsec peer set 0 address=\$RemoteSite0"
add name="Tunnel 1" policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    source=":global LocalSite1 [:resolve x1.dyndns.org]\r\
    \n:global RemoteSite1 [:resolve y2.dyndns.org]\r\
    \n/ip ipsec policy set 1 sa-dst-address=\$RemoteSite1 sa-src-address=\$Loc\
    alSite1 \r\
    \n/ip ipsec peer set 1 address=\$RemoteSite1\r\
    \n"
add name="Tunnel 2" policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    source=":global LocalSite2 [:resolve x1.dyndns.org]\r\
    \n:global RemoteSite2 [:resolve y3.dyndns.org]\r\
    \n/ip ipsec policy set 2 sa-dst-address=\$RemoteSite2 sa-src-address=\$Loc\
    alSite2\r\
    \n/ip ipsec peer set 2 address=\$RemoteSite2\r\
    \n"
 
Moogman
just joined
Posts: 13
Joined: Sat Nov 24, 2012 2:03 am

Re: dynDNS Update Script

Sat Dec 01, 2012 12:45 am

I have a problem with the script for RouterOs5

http://wiki.mikrotik.com/wiki/Dynamic_D ... for_dynDNS

Please correct me if iam wrong.

But this script is writing into the flash everytime it is called.
It writes some files to the flash file system.

I think this is not good if the script runs every minute, this will damage the flash with the time.

I hope Mikrotik will do a free configurable DYNDNS client (wich only runs complete in the ram).
 
vortex1
just joined
Posts: 20
Joined: Tue Sep 28, 2010 10:07 am

Re: dynDNS Update Script

Sat Dec 01, 2012 10:35 am

hi. i am trying to setup dyndns to rb750 without success.
the user details are correct since i am checking them on different routers.
these are the steps i followed.
-in winbox i created a new script called dynDNS. there i have added the script from the creator of this thread, but i chenged to my username/passwd/hostname
-then i clicked on the script to run now, to check if it is working. nothing happens. it does not make the correct resolution of the ip to hostname, since dyndns did not get the update.
-in terminal i added the script to run every 1 min.
-reboot

unfortunately dyndns it does not get the info of my new ip to resolve it, everytime i reboot.
how can i fix this issue?
 
samuelongui
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Wed Mar 02, 2011 9:07 pm

Re: dynDNS Update Script

Tue Dec 11, 2012 11:23 am

dyndns didn't work for me. Now I use changeip and it's working OK
 
yohanvil
just joined
Posts: 7
Joined: Fri Aug 21, 2009 3:22 pm

Re: dynDNS Update Script

Tue Feb 05, 2013 7:43 am

hello Samuel

Are you using RB750 5.22 Version?

thanks.
 
janx
just joined
Posts: 2
Joined: Sat Mar 16, 2013 4:24 pm

Re: dynDNS Update Script

Sat Mar 16, 2013 5:11 pm

hi. i am trying to setup dyndns to rb750 without success.
the user details are correct since i am checking them on different routers.
these are the steps i followed.
-in winbox i created a new script called dynDNS. there i have added the script from the creator of this thread, but i chenged to my username/passwd/hostname
-then i clicked on the script to run now, to check if it is working. nothing happens. it does not make the correct resolution of the ip to hostname, since dyndns did not get the update.
-in terminal i added the script to run every 1 min.
-reboot

unfortunately dyndns it does not get the info of my new ip to resolve it, everytime i reboot.
how can i fix this issue?
Hi, I can confirm that following script works on rb751G-2HnD with RouterOS v5.24. However, remember to check that this script has proper line endings: \r\n. If you are unix or mac user and copied the script from webpage directly to winbox then it probably won't work. Before pasting use external text editor to convert line endings to \r\n.
Hope this helps.

Script [can also be found in earlier posts in this thread]:
# Set needed variables
:local username "xxxxxxxxxx"
:local password "yyyyyyyy"
:local hostname "yyyyyyyyyyyyy"
:global ddnsinterface "xxxxxxxxx e.g. pppoe-out1 xxxxxxx"
:global ddnsip ""

:global dyndnsForce
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];
:log info ("UpdateDynDNS: currentIP = $ddnsip")

#get IP from DynDNS for my hostname
:local resolvedIP [:resolve $hostname]
:log info ("UpdateDynDNS: resolved IP =$resolvedIP")

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($ddnsip != $resolvedIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$ddnsip" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
Cheers,
 
ZhenXlogic
just joined
Posts: 5
Joined: Sat Sep 29, 2012 7:59 pm
Location: Néa Smírni, Athens - Greece

Re: dynDNS Update Script

Sat Mar 30, 2013 7:29 pm

Hello,

I have an RB750 with OS 6.0RC12 i try the scripts that found in this topic but no success.

Can some one confirm if the scripts work with OS 6.0RC12?
 
User avatar
satman1w
Member Candidate
Member Candidate
Posts: 279
Joined: Mon Oct 02, 2006 11:47 am

Re: dynDNS Update Script

Tue Apr 02, 2013 5:05 pm

Hello,

I have an RB750 with OS 6.0RC12 i try the scripts that found in this topic but no success.

Can some one confirm if the scripts work with OS 6.0RC12?
Try this.... it is slightly modified, but tested yesterday on V.6.rc11
(remember, your pppoe interface must be renamed to "ADSL" and you have toi edit "+++something+++" variables....
-------------------------------------------------------------------------------------------------------------------
#SuperScript V.3.0 [20130330]

#Variables definition

:global adslip
:global adsllastip
:global datum [/system clock get date]
:global vrijeme [/system clock get time] 
:global ime [/system identity get name]

#IF lastip is non existant - set it to "0"
:if ([ :typeof $adsllastip ] = nil ) do={ :global adsllastip "0" }
 
#Set variable with actual ADSL address
:global adslip [ /ip address get [/ip address find interface=ADSL ] address ]

#If not existant - log it
:if ([ :typeof $adslip ] = nil ) do={
 :log error "=== No IP on ADSL Interface"
} else={

#...if existsi
:if ($adslip != $adsllastip) do={

:local dynuser "+++dynuser+++" 
:local dynpass "+++dynpass+++"
:local dynhost "+++dynhost+++"

:log info "=== Updating dns record at DynDNS"
:local str "/nic/update?hostname=$dynhost&myip=$adslip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" 
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$dynuser password=$dynpass dst-path=("/DynDNS.".$dynhost)


:local mailsender "$ime@something.com";
:local mailrec +++mailrec@something.com+++;
:local mailsubject "IP adresa from /$ime/ $datum $vrijeme";
:local mailbody "$adslip";
:local mailserver [:resolve +++mymailserver+++];
:local mailuser +++mymailuser+++;
:local mailpass +++mailpass+++;

:log info "=== Sending mail"
/tool e-mail send from=$mailsender to=$mailrec subject=$mailsubject body=$mailbody server=$mailserver user=$mailuser password=$mailpass;

#Moving new IP to lastip variable
:global adsllastip "$adslip"

} else={ 
:log info "=== No IP update needed"
}
}
 
Catsix
just joined
Posts: 4
Joined: Fri Apr 12, 2013 1:43 pm

Re: dynDNS Update Script

Fri Apr 12, 2013 2:13 pm

Just my version of the script. Runs on a RB750GL OS v5.20.
It probably could use some finetuning.
Remark: I used the Google nameserver for resolving. It was not working without it, have not figured out why yet. There is only a tiny delay when the IP changes.
Ramark 2: The interface 1 needs to be connected to the WAN (external IP). Because I'm not using the checkip service in case of NAT.
# Set variables
:local username "username";
:local password "password";
:local hostname "hostname";
:local inetinterface "ether1-gateway";
:local sysdate [/system clock get date];
:local systime [/system clock get time];
:local sysname [/system identity get name];

:local dyndnsForce;

#:set dyndnsForce true;

# Print debug info
#:log info ("DynDNS: username = $username");
#:log info ("DynDNS: password = $password");
#:log info ("DynDNS: hostname = $hostname");

# Check if WAN interface is running
:if ([/interface get $inetinterface value-name=running]) do={

# Get the current IP on the WAN interface
 :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address];

# Strip the net mask off the IP address
 :set currentIP [:pick $currentIP 0 [:find $currentIP "/"]];
 :log info ("DynDNS: current WAN IP = $currentIP");

# Get resolved IP
 :local resolvedIP [:resolve domain-name=$hostname server=8.8.8.8];
 :log info ("DynDNS: resolved IP = $resolvedIP");

# Determine if dyndns update is needed
# Dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
 :if (($currentIP != $resolvedIP) || ($dyndnsForce = true)) do={
  :set dyndnsForce false;
  /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
  src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
  dst-path="/dyndns.txt";
  :delay 1;
  :local result [/file get dyndns.txt contents]
  :log info ("DynDNS: Update needed")
  :log info ("DynDNS: Update Result: ".$result)
# Send mail
  :local mailsender "routerboard@domain";
  :local mailrec "mailbox@domain";
  :local mailsubject "IP address from /$sysname/ $sysdate $systime";
  :local mailbody "$currentIP";
  :local smtpserver "mailserver.domain";
  :local mailserver [:resolve domain-name=$smtpserver server=8.8.8.8];
  :log info ("DynDNS: Sending mail");
  /tool e-mail send from=$mailsender to=$mailrec subject=$mailsubject body=$mailbody server=$mailserver;
} else={
  :log info ("DynDNS: No update needed");
}
} else={
    :log info ("DynDNS: $inetinterface is not currently running");
}
 
mwieting
just joined
Posts: 9
Joined: Fri May 03, 2013 12:54 am

Re: dynDNS Update Script

Tue May 07, 2013 11:22 pm

I've been using the script below but havent had any luck. When I look at the log all i get is
dyndns-update: user name XXXXX
dyndns-update:password XXXX
dyndns-update:XXXXXX

And my nothing else shows up in the log nor does my IP update.
# Set needed variables
:local username "dyndnsUsername"
:local password "dyndnsPassword"
:local hostname "hostname.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("dyndns-update: username = $username")
:log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")

# 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 "dyndns-update: currentIP = $currentIP"

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
:local result [/file get dyndns.txt contents]
:log info ("dyndns-update: Dyndns update needed")
:log info ("dyndns-update: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("dyndns-update: No dyndns update needed")
}
 
zoltix
just joined
Posts: 20
Joined: Mon Jul 01, 2013 11:10 pm

Re: dynDNS Update Script

Thu Sep 19, 2013 11:00 am

My Version for working with EuroDns, AsiaDns....

On WebSite(Eurodns.com) , signin, -> Control Panel->Domain Portfolio-> Manage Zone
Setting/adding record A or AAA -> Dynamic =active


https://www.eurodns.com/products/plugins/documentation/
http://sourceforge.net/apps/trac/ddclient/wiki/Usage

RouterBoard RB2011 Vers 6.3


:local username "user";
:local password "pw";
:local hostname "subnet.domain.be";
:local inetinterface "ether1-gateway";
:local sysdate [/system clock get date];
:local systime [/system clock get time];
:local sysname [/system identity get name];

:local dyndnsForce;

#:set dyndnsForce true;

# Print debug info
#:log info ("EuroDNS: username = $username");
#:log info ("EuroDNS: password = $password");
#:log info ("EuroDNS: hostname = $hostname");

# Check if WAN interface is running
 :if ([/interface get $inetinterface value-name=running]) do={

# Get the current IP on the WAN interface
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address];

# Strip the net mask off the IP address
 :set currentIP [:pick $currentIP 0 [:find $currentIP "/"]];
 :log info ("EuroDNS: current WAN IP = $currentIP");

# Get resolved IP
 :local resolvedIP [:resolve domain-name=$hostname server=8.8.8.8];
 :log info ("EuroDNS: resolved IP = $resolvedIP");

# Determine if dyndns update is needed
# Dyndns updater request details https://www.eurodns.com/products/plugins/documentation/ and http://sourceforge.net/apps/trac/ddclient/wiki/Usage
 :if (($currentIP != $resolvedIP) || ($dyndnsForce = true)) do={
  :set dyndnsForce false;
 /tool fetch  user=$username password=$password url="http://eurodyndns.org/update/?hostname=$hostname&myip=$currentIP" dst-path="/eurodns.txt";
  :delay 1;
  :local result [/file get dyndns.txt contents]
  :log info ("EuroDNS: Update needed")
  :log info ("EuroDNS: Update Result: ".$result)
# Send mail
  :local mailsender "routerboarb@lli.be";
  :local mailrec "xx@xx.be";
  :local mailsubject "IP address from /$sysname/ $sysdate $systime";
  :local mailbody "$currentIP";
  :local smtpserver "smtp.voo.be";
  :local mailserver [:resolve domain-name=$smtpserver server=8.8.8.8];
  :log info ("EuroDNS: Sending mail");
  /tool e-mail send from=$mailsender to=$mailrec subject=$mailsubject body=$mailbody ; #configure Email Setting  /tool e-mail 
} else={
  :log info ("EuroDNS: No update needed");
}
} else={
    :log info ("DynDNS: $inetinterface is not currently running");
}
}
 
Asenki
just joined
Posts: 3
Joined: Sun Dec 07, 2014 2:49 pm

Re: dynDNS Update Script

Sun Dec 07, 2014 3:22 pm

Hi all,
The script is working fine, but i've got "badauth" every times. I've checked username/pass, i can login to dyn services use with it.
BUT!
My dyn account's password contain special character, so, many hours later found a solution:
In the script use special characters with escape, as
:global ddnspass "pa\$\$word"
instead
:global ddnspass "pa$$word"
:)
Sorry if obvious for everyone, i am a newbie on MikroTik.
 
Hatchetz
just joined
Posts: 3
Joined: Tue Dec 23, 2014 11:25 am

Re: dynDNS Update Script

Tue Dec 23, 2014 11:32 am

HI all
Last edited by Hatchetz on Tue Dec 23, 2014 12:48 pm, edited 1 time in total.
 
Hatchetz
just joined
Posts: 3
Joined: Tue Dec 23, 2014 11:25 am

Re: dynDNS Update Script

Tue Dec 23, 2014 11:32 am

I tried to setup dynDNS update but smthng goes wrong:
i tried all scripts
my hostname is NAME.HOMEIP.NET
my acc in dyn.com is SECONDNAME

as i thought, right script is:
# Define User Variables
:global ddnsuser "SECONDNAME"
:global ddnspass "PASSWORDtoDYN.COM"
:global ddnshost "NAME.homeip.net"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }

:global ddnsinterface
:global ddnssystem ("mt-" . [/system package get system version] )

# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global ddnsinterface [/ip route get $int interface]
  }
}

# Grab the current IP address on that interface.
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Sending UPDATE!"
    :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
    /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
        password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ddnslastip $ddnsip
  }
}
is it?

But it's not work.

Where is a mistake?
Last edited by Hatchetz on Tue Dec 23, 2014 12:49 pm, edited 1 time in total.
 
Hatchetz
just joined
Posts: 3
Joined: Tue Dec 23, 2014 11:25 am

Re: dynDNS Update Script

Tue Dec 23, 2014 12:47 pm

input does not match any value of value-name

thats all i have after running script

routeros 6.23
rb951ui-2hnd
 
noremacyug
newbie
Posts: 34
Joined: Mon Dec 22, 2014 10:48 pm

Re: dynDNS Update Script

Sun Dec 28, 2014 3:51 am

(edit)- got it working via another script i found that is for dyndns service.


just got my 2011UiAS-2HnD in and have it connected to the web and my local network seems working thus far. trying to get dyndns working. i've added the script listed below via the webgui and changed the variables that i'm aware need changing. i'm wanting to have the ip on my wan port updated to dyndns. i'm sure i'm leaving out some steps and would greatly appreciate help. loving the 2011UiAS-2HnD.



:global ddnsuser "theddnsusername"
:global ddnspass "theddnspassword"
:global theinterface "interfacename"
:global ddnshost blabla.dyndns.org
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynDNS: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}

:if ($ipddns != $ipfresh) do={
:log info ("DynDNS: IP-DynDNS = $ipddns")
:log info ("DynDNS: IP-Fresh = $ipfresh")
:log info "DynDNS: Update IP needed, Sending UPDATE...!"
:global str "/nic/update\?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
:delay 1
:global str [/file find name="DynDNS.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynDNS: IP updated to $ipfresh!"
} else={
:log info "DynDNS: dont need changes";
}
}
 
User avatar
Akangage
newbie
Posts: 45
Joined: Tue May 29, 2007 2:33 pm
Location: Indonesia
Contact:

Re: dynDNS Update Script

Sat Feb 28, 2015 2:29 am

All of dyndns script broken since 6.25 anyone have the update one?

Ah... it solved, the problem laid in "Dyndns updater client key", I need to generate new key. Its worked now.
 
LAD75
just joined
Posts: 6
Joined: Sun Jun 28, 2015 7:32 pm

Re: dynDNS Update Script

Sun Jun 28, 2015 7:43 pm

I try to use a script to update the Dyn-dns, and none one of them does not run from the scheduler.

first:
:local username "login"
:local password "pass"
:global hostname "my.com" 

:global dyndnsForce
:global previousIP
:local resolvedIP [:resolve $hostname]

#print some debug
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")
:log info ("UpdateDynDNS: resolvedIP = $resolvedIP")

# 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 "" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!
# Edit: Not really needed anymore... the result is not equal... Update will happen.

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
#This is where we check the DNS record against actual result. Thanks to jimstolz76
:if (($currentIP != $resolvedIP) || ($dyndnsForce = true)) do={
  :set dyndnsForce false
  :set previousIP $currentIP
  /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
  src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
  :local result [/file get dyndns.txt contents]
  :log info ("UpdateDynDNS: Dyndns update needed")
  :log info ("Update Result: " . $result)
  :put ("Dyndns Update Result: " . $result)
} else= {
  :log info ("UpdateDynDNS: No dyndns update needed")
}
second:
# Define User Variables
:global ddnsuser "user"
:global ddnspass "passwd"
:global ddnshost "domain.com"
:global ddnsinterface "beeline-l2tp"
:global ddnsip
:global ddnslastip
:if ([:typeof $ddnslastip] = nil) do={ :global ddnslastip "0.0.0.0/0" }  
# Grab the current IP address on that interface.
:global ddnsip [/ip address get [/ip address find interface=$ddnsinterface] address]
:if ([:typeof $ddnsip] = nil) do={
  :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Previous IP was: $ddnslastip"
    :log info "DynDNS: Sending new IP:$ddnsip UPDATE!"
    /tool fetch keep-result=no url="http://$ddnsuser:$ddnspass@204.13.248.112/nic/update\?hostname=$ddnshost"
    :global ddnslastip $ddnsip
 } else={
:log info "DDNS: No update required."
  }
}
run from the console script works OK. access rights everywhere exhibited maximum.
what am I doing wrong?
 
LAD75
just joined
Posts: 6
Joined: Sun Jun 28, 2015 7:32 pm

Re: dynDNS Update Script

Mon Jun 29, 2015 6:10 am

I'm trying to configure automatic updates DNS from Dyn-DNS.
I took as a basis for two of the script. I add them to the scheduler, exposing the maximum rights. no one does not run.
the script only works if i run it from the console.

first
:global ddnsuser "user"
:global ddnspass "passwd"
:global theinterface "beeline-l2tp"
:global ddnshost devabap.com
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("DynDNS: No ip address on $theinterface .")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
    :set ipfresh [:pick $ipfresh 0 $i];
      } 
}
 
:if ($ipddns != $ipfresh) do={
    :log info ("DynDNS: IP-DynDNS = $ipddns")
    :log info ("DynDNS: IP-Fresh = $ipfresh")
   :log info "DynDNS: Update IP needed, Sending UPDATE...!"
   :global str "/nic/update\?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
   /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
         password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :global str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ipddns $ipfresh
  :log info "DynDNS: IP updated to $ipfresh!"
    } else={
     :log info "DynDNS: dont need changes";
    }
} 
second
# Define User Variables
:global ddnsuser "user"
:global ddnspass "passwd"
:global ddnshost "devabap.com"
:global ddnsinterface "beeline-l2tp"
:global ddnsip
:global ddnslastip
:if ([:typeof $ddnslastip] = nil) do={ :global ddnslastip "0.0.0.0/0" }  
# Grab the current IP address on that interface.
:global ddnsip [/ip address get [/ip address find interface=$ddnsinterface] address]
:if ([:typeof $ddnsip] = nil) do={
  :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
    :log info "DynDNS: Previous IP was: $ddnslastip"
    :log info "DynDNS: Sending new IP:$ddnsip UPDATE!"
    /tool fetch keep-result=no url="http://$ddnsuser:$ddnspass@204.13.248.112/nic/update\?hostname=$ddnshost"
    :global ddnslastip $ddnsip
 } else={
:log info "DDNS: No update required."
  }
}
and script screen

Image

Pictures of the script can be seen that it is run - the counter increases.
 
dadoremix
Member Candidate
Member Candidate
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: dynDNS Update Script

Sun Jul 12, 2015 1:36 pm

anyone have full script for 6.30 version od mikrotik
old has stop woking
# Set needed variables
:local username yyyy
:local password zzzzzz
:local hostname xxx.dyndns.tv

:global dyndnsForce
:global previousIP 

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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"
:delay 1
: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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :set dyndnsForce false
   :set previousIP $currentIP
   :log info "$currentIP or $previousIP"
   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
      dst-path="/dyndns.txt"
   :delay 1
   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
   :put ("Dyndns Update Result: ".$result)
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
}
 
nikkarad
just joined
Posts: 1
Joined: Sun Jul 05, 2015 1:32 pm

Re: dynDNS Update Script

Sun Jul 12, 2015 4:00 pm

I have the same problem, my dyndns hostname stopped updating. I 've tried about 8 different scripts and none of them worked. I have a dual wan setup on my rb750gl but a while ago dyndns worked fine. Does anybody know what happened?
 
sv000008
just joined
Posts: 8
Joined: Sat Jul 18, 2015 6:44 pm

Re: dynDNS Update Script

Sat Jul 18, 2015 6:48 pm

I'm having the same problem. All was working winth v6.29.1. One revision later (6.30.1) and it's broken :(
 
gbr
just joined
Posts: 8
Joined: Sun Jul 19, 2015 10:34 am
Location: Wellington. New Zealand

Re: dynDNS Update Script

Sun Jul 19, 2015 11:29 am

I have the same problem, my dyndns hostname stopped updating. I 've tried about 8 different scripts and none of them worked. I have a dual wan setup on my rb750gl but a while ago dyndns worked fine. Does anybody know what happened?
I don't know what happened, but I noticed the same problem and hit it with a hammer of suitable size.

Also the global previousIP doesn't appear to persist between invocations of the script.

I have made, and tested, two changes to the script:
  1. instead of the /fetch command in the quoted script I generate a URL as specified by Dyn.com here: http://www.dyndns.com/developers/specs/syntax.html. This works for me.
  1. To address the persistence issue I have written code to parse dyndns.txt to extract the IP address or set it to "0.0.0.0" if the file doesn't exist.
Apologies if the format is funny, this is my first post and I don't understand the formatting controls...

Regards
Graeme
Last edited by gbr on Tue Jul 21, 2015 10:46 am, edited 1 time in total.
 
RackKing
Member
Member
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

Re: dynDNS Update Script

Mon Jul 20, 2015 2:29 pm

@gbr

did you get it working - can you share?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Mon Jul 20, 2015 11:43 pm

Have you tried to extend delays from 1 second to 2 seconds? I suggest that.
 
gbr
just joined
Posts: 8
Joined: Sun Jul 19, 2015 10:34 am
Location: Wellington. New Zealand

Re: dynDNS Update Script

Tue Jul 21, 2015 3:05 am

@gbr

did you get it working - can you share?
Edit: remove spurious blank lines introduced by cut'n'paste.

This was before I saw the email suggesting an increase in the delay.

This code is in production on two routers, one running 6.30.1 and on 6.30.
# Based on a script found on the Internet.Will add attribution if I find it.
# Changed 20150719 by Graeme Ruthven (graeme@kula.co.nz)
# Modified to:
# - update using authentication in URL as original method appeared to stop working.
#   This was about the time of the RouterOS 6.30 release, but may be unrelated.
# - Get the previous IP from the contents of the dyndns.txt file, as the global variable
#   doesn't appear to persist.
#
# Reference: https://help.dyn.com/remote-access-api/perform-update/

:local username "<dyn.com user name>"
:local password "<dyn.com password or, better, Updater Client Key>"
:local hostname "<dyn.com host name>"
:local emailAddress "<where to send notifications>"

:local url "dummy"
:local previousIP

:global dyndnsForce

:set dyndnsForce false

:log info ("UpdateDynDNS starts.")

# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
#:log info ("UpdateDynDNS: hostname = $hostname")
#:log info ("UpdateDynDNS: previousIP = $previousIP")

# I have some doubt over the persistence of the global previousIP.
# This value should be stored in /dyndns.txt after the last update attempt,
# preceded by the status and a space.
# For status values see: https://help.dyn.com/remote-access-api/return-codes/

:if ([:len [/file find name=dyndns.txt]] > 0) do={
   :local ipfile [/file get dyndns.txt contents]
   :local ipstart ([find $ipfile " " -1] + 1)
   :local ipend [:len $ipfile]
   :set previousIP [:pick $ipfile $ipstart $ipend]
} else={
   :set previousIP "0.0.0.0"
}

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyn.com" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
: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]

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :log info ("Changing IP from $previousIP to $currentIP.")
   :set dyndnsForce false
   :set url "http://$username:$password@members.dyndns.org/nic/update?hostname=$hostname&myip=$currentIP&wildcard=no"
   /tool fetch url=$url mode=http dst-path="/dyndns.txt"
  
# Original code:
#   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
#      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
#      dst-path="/dyndns.txt"

   :delay 1

 #  :set previousIP $currentIP

   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)

# email result:
   :local output "DynDNS Update Result: $result"
   /tool e-mail send to="$emailAddress" subject="DynDNS update $currentTime" body="$output"
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
}
 
RackKing
Member
Member
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

Re: dynDNS Update Script

Wed Jul 22, 2015 2:59 pm

@gbr - thank you very much for posting this. I kind of works for me.... have a couple of questions. Note: I am a novice at scripting and still learning.

So I have poured over this sever times - it has been a great learning opportunity. As I understand it this -
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyn.com" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]
goes out to dyndns, grabs the ip address from the hostname and then creates a file named "dyndns.checkip.html". I assumed this should be what shows up on your dyndns hosts page. Mine does not...

Also - what does the :local result command do?

When I manually change (break) the IP address on the dyndns page to say 1.1.1.1 - it pulls the old IP address still. When I do an nslookup on the hostname it is correct @ 1.1.1.1.

So when the compare if statement runs - it makes no changes because currentIP and previousIP are the same.

If I delete the dyndns.txt file and the dyndns.checkip.html file the script works - but only the first time I run it.

Further - If I issue global resolvedIP [:resolve $hostname] - it will pull the correct dyndns address of 1.1.1.1

Is that why mine does not work - is this a dyndns issue? Any help appreciated.
 
docwhogr
just joined
Posts: 8
Joined: Fri Jul 24, 2015 11:38 pm

Re: dynDNS Update Script

Fri Jul 24, 2015 11:42 pm

starting from v6.30 you have to specify host=members.dyndns.org for this to work
or i guess is a bug...
 
gbr
just joined
Posts: 8
Joined: Sun Jul 19, 2015 10:34 am
Location: Wellington. New Zealand

Re: dynDNS Update Script

Mon Jul 27, 2015 4:05 am

@gbr - thank you very much for posting this. I kind of works for me.... have a couple of questions. Note: I am a novice at scripting and still learning.

So I have poured over this sever times - it has been a great learning opportunity. As I understand it this -
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyn.com" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]
goes out to dyndns, grabs the ip address from the hostname and then creates a file named "dyndns.checkip.html". I assumed this should be what shows up on your dyndns hosts page. Mine does not...
No. Go to http://checkip.dyn.com in a browser and you'll see that it returns the current IP address of your Internet connection.
Also - what does the :local result command do?
Declares a local variable named "result".

If you're asking about the rest of the command in the script, it copies the contents of the file named "dyndns.checkip.html" into the variable.
When I manually change (break) the IP address on the dyndns page to say 1.1.1.1 - it pulls the old IP address still. When I do an nslookup on the hostname it is correct @ 1.1.1.1.

So when the compare if statement runs - it makes no changes because currentIP and previousIP are the same.
See above. You are misinterpreting the purpose of checkip.dyn.com.
If I delete the dyndns.txt file and the dyndns.checkip.html file the script works - but only the first time I run it.
Look at the contents of both dyndns.txt and dyndns.checkip.html after a script run.

In particular, if dyndns.txt has anything other than "good <ip address>" (signifying a successful update) or "nochg <ip address>" (signifying that no update is required) go to https://help.dyn.com/remote-access-api/return-codes/ and work out why the update was unsuccessful.

For debugging try putting in some ":log info ..." commands to put the values of various variables in the log file and watch while the script runs to see that they are as expected.
Further - If I issue global resolvedIP [:resolve $hostname] - it will pull the correct dyndns address of 1.1.1.1

Is that why mine does not work - is this a dyndns issue? Any help appreciated.
Sounds as if resolve is acting as expected - doing a DNS lookup on your host name. I doubt that it's a dyn.com error.

I have the script I provided working successfully on three routers.
Last edited by gbr on Sun Aug 02, 2015 11:58 am, edited 2 times in total.
 
dadoremix
Member Candidate
Member Candidate
Posts: 133
Joined: Sat May 14, 2011 11:31 am

dynDNS Update Script

Mon Jul 27, 2015 9:06 am

Me too, last script post here works excelent
Tnx
 
RackKing
Member
Member
Posts: 380
Joined: Wed Oct 09, 2013 1:59 pm

Re: dynDNS Update Script

Wed Jul 29, 2015 2:52 pm

@gbr - thank you very much for posting this. I kind of works for me.... have a couple of questions. Note: I am a novice at scripting and still learning.

I have the script I provided working successfully on three routers.
Thanks very much GBR for the help and clarification.
 
Cormacs
newbie
Posts: 42
Joined: Sat Aug 29, 2015 2:27 am

Re: dynDNS Update Script

Thu Sep 10, 2015 4:42 am

I need some help. I have a dual PPPOE WAN set-up. I have modified a few scripts on here to make my own. I can't seem to find a proper dyndns script for a dual wan set-up. My one WAN I use to service all of my ports, my second WAN I would still like it's IP updated to a separate alias on DynDNS just for a just in case. Maybe my first WAN fails and I want to come in on the second one. None of the services are important to make an elaborate fail over system, I just want DynDNS to have both IP's. Here is what I got so far...

:local ddnsuser "******"
:local ddnspass "*******"
:local theinterface1 "********"
:local theinterface2 "*********"
:local ddnshost1 "**********"
:local ddnshost2 "*********"
:local ipddns1 [:resolve $ddnshost1];
:local ipddns2 [:resolve $ddnshost2];
:local ipfresh1 [ /ip address get [/ip address find interface=$theinterface1 ] address ]
:local ipfresh2 [ /ip address get [/ip address find interface=$theinterface2 ] address ]
:if ([ :typeof $ipfresh1 ] = nil ) do={
:log info ("DynDNS1: No ip address on $theinterface1 .")
} else={
:for i from=( [:len $ipfresh1] - 1) to=0 do={
:if ( [:pick $ipfresh1 $i] = "/") do={
:set ipfresh1 [:pick $ipfresh1 0 $i];
}
}

:if ($ipddns1 != $ipfresh1) do={
:log info ("DynDNS1: IP-DynDNS = $ipddns1")
:log info ("DynDNS1: IP-Fresh = $ipfresh1")
:log info "DynDNS1: Update IP needed, Sending UPDATE...!"
:local str "/nic/update?hostname=$ddnshost1&myip=$ipfresh1&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=("/DynDNS.".$ddnshost1)
:delay 1
:local str [/file find name="DynDNS.$ddnshost1"];
/file remove $str
:global ipddns1 $ipfresh1
:log info "DynDNS1: IP updated to $ipfresh1!"
} else={
:log info "DynDNS1: dont need changes";
}
}

:if ([ :typeof $ipfresh2 ] = nil ) do={
:log info ("DynDNS2: No ip address on $theinterface2 .")
} else={
:for i from=( [:len $ipfresh2] - 1) to=0 do={
:if ( [:pick $ipfresh2 $i] = "/") do={
:set ipfresh2 [:pick $ipfresh2 0 $i];
}
}

:if ($ipddns2 != $ipfresh2) do={
:log info ("DynDNS2: IP-DynDNS = $ipddns2")
:log info ("DynDNS2: IP-Fresh = $ipfresh2")
:log info "DynDNS2: Update IP needed, Sending UPDATE...!"
:local str "/nic/update?hostname=$ddnshost2&myip=$ipfresh2&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
password=$ddnspass dst-path=("/DynDNS.".$ddnshost2)
:delay 1
:local str [/file find name="DynDNS.$ddnshost2"];
/file remove $str
:global ipddns2 $ipfresh2
:log info "DynDNS2: IP updated to $ipfresh2!"
} else={
:log info "DynDNS2: dont need changes";
}
}


So far it works great with one minor hiccup. One of the address' will always resolve incorrectly. Even though if I ping the address I get the proper IP back. Microtik always resolves the wrong address and thinks it requires an update. It is updating both address just find, I'm just worried DynDNS will black list me because of a minutely update. It always comes up...
DynDNS2: IP-DynDNS = old ip from a while ago
DynDNS2: IP-Fresh = Proper IP as obtained from the interface
Update require
continues to update.

The update process for both interfaces goes through without a problem and I can resolve the host no problem. Just for some reason the script doesn't resolve the ip properly and forces an unrequired update.
 
Cormacs
newbie
Posts: 42
Joined: Sat Aug 29, 2015 2:27 am

Re: dynDNS Update Script

Thu Sep 10, 2015 12:18 pm

It seems to have fixed itself overnight. Now it resolves both hosts no problem. I have been reading that these routers some times have issues with dns holding on to cached sites? Is this possible my issue?
 
Cormacs
newbie
Posts: 42
Joined: Sat Aug 29, 2015 2:27 am

dynDNS Update Script

Thu Sep 10, 2015 12:46 pm

I figured my own issue out. I realized I had the dyndns ttl set to 4 hours, so the router was holding on to the cached DNS value for 4 hours. I set it back done to 60 seconds, now it only does it for a max of 60 seconds.


Sent from my iPhone using Tapatalk
 
mike8itall
just joined
Posts: 2
Joined: Thu Dec 31, 2015 8:39 pm

Re: dynDNS Update Script

Thu Dec 31, 2015 9:09 pm

@gbr

Thanks a lot gbr. For others information, after going down the line and trying all the code in this thread, I was finally able to verify this code as working properly with RB2011UiAS v6.33.3 so far.



Edit: remove spurious blank lines introduced by cut'n'paste.

This was before I saw the email suggesting an increase in the delay.

This code is in production on two routers, one running 6.30.1 and on 6.30.
# Based on a script found on the Internet.Will add attribution if I find it.
# Changed 20150719 by Graeme Ruthven (graeme@kula.co.nz)
# Modified to:
# - update using authentication in URL as original method appeared to stop working.
#   This was about the time of the RouterOS 6.30 release, but may be unrelated.
# - Get the previous IP from the contents of the dyndns.txt file, as the global variable
#   doesn't appear to persist.
#
# Reference: https://help.dyn.com/remote-access-api/perform-update/

:local username "<dyn.com user name>"
:local password "<dyn.com password or, better, Updater Client Key>"
:local hostname "<dyn.com host name>"
:local emailAddress "<where to send notifications>"

:local url "dummy"
:local previousIP

:global dyndnsForce

:set dyndnsForce false

:log info ("UpdateDynDNS starts.")

# print some debug info
#:log info ("UpdateDynDNS: username = $username")
#:log info ("UpdateDynDNS: password = $password")
#:log info ("UpdateDynDNS: hostname = $hostname")
#:log info ("UpdateDynDNS: previousIP = $previousIP")

# I have some doubt over the persistence of the global previousIP.
# This value should be stored in /dyndns.txt after the last update attempt,
# preceded by the status and a space.
# For status values see: https://help.dyn.com/remote-access-api/return-codes/

:if ([:len [/file find name=dyndns.txt]] > 0) do={
   :local ipfile [/file get dyndns.txt contents]
   :local ipstart ([find $ipfile " " -1] + 1)
   :local ipend [:len $ipfile]
   :set previousIP [:pick $ipfile $ipstart $ipend]
} else={
   :set previousIP "0.0.0.0"
}

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyn.com" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
: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]

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :log info ("Changing IP from $previousIP to $currentIP.")
   :set dyndnsForce false
   :set url "http://$username:$password@members.dyndns.org/nic/update?hostname=$hostname&myip=$currentIP&wildcard=no"
   /tool fetch url=$url mode=http dst-path="/dyndns.txt"
  
# Original code:
#   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
#      src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
#      dst-path="/dyndns.txt"

   :delay 1

 #  :set previousIP $currentIP

   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)

# email result:
   :local output "DynDNS Update Result: $result"
   /tool e-mail send to="$emailAddress" subject="DynDNS update $currentTime" body="$output"
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
}
[/quote]
 
mike8itall
just joined
Posts: 2
Joined: Thu Dec 31, 2015 8:39 pm

Re: dynDNS Update Script

Thu Dec 31, 2015 10:14 pm

I have the RB2011UiAS running version 6.33.3, and I'm having issues getting the scheduler to run my dynDNS script.

I've seen a couple others having issues scheduling their script.
Mine won't work, and I don't think I can blame the scheduler.
When ran from the terminal, the feedback is "no such item"

I have my script named exactly "dynDNS"
I can run the script under the script configuration window in the script list, and it works properly.
It properly logs that it updated my DNS server, and it also shows successfully updated in my dyn.com account.

So the script is there. The file really does exist.
Does anybody know why I might get this result in the terminal?

[admin@MikroTik] > /system script run dynDns
no such item
[admin@MikroTik] >
 
iwancs
just joined
Posts: 3
Joined: Tue Feb 16, 2016 2:48 am

Re: dynDNS Update Script

Sat Apr 23, 2016 2:11 pm

If anyone still having problem updating dynDNS, here is a working code i've tried with some help of others in many forums and article, i've tried this on RouterBoard 750G r2 ver. 3.23

# Set needed variables
:local username "DYNDNSUSER"
:local password "DYNDNSPASSWORD"
:local hostname "DYNDNSHOSTNAME"
:local previousIP [:put [:resolve $hostname]];
:delay 1
:global dyndnsForce
:global previousIP

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# 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"
:delay 1
: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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info "$currentIP or $previousIP"
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
src-path="nic/update?system=dyndns&hostname=$hostname&myip=$currentIP&wildcard=no" \
dst-path="/dyndns.txt"
:delay 1
:local result [/file get dyndns.txt contents]
:log info ("UpdateDynDNS: Dyndns update needed")
:log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("UpdateDynDNS: No dyndns update needed")
}
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19106
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: dynDNS Update Script

Sun Mar 11, 2018 7:23 pm

I figured my own issue out. I realized I had the dyndns ttl set to 4 hours, so the router was holding on to the cached DNS value for 4 hours. I set it back done to 60 seconds, now it only does it for a max of 60 seconds.


Sent from my iPhone using Tapatalk
What does it mean dyndns ttl set to 4 hours?
I looked around WINBOX and could not find a dyndns ttl? Is this prior to 4.61 syntax?

By the way this chaps script (cormac) seemed decent for my situation dual wan.
My one concern is that I am not sure if the information being sent is encrypted or not and should I worry?
I am using the update key provided vice password.
 
zivtal
Frequent Visitor
Frequent Visitor
Posts: 57
Joined: Sun Feb 05, 2017 6:22 pm

Re: dynDNS Update Script

Tue Mar 20, 2018 12:52 pm

I have made this script ddns.rsc, It's allow you to use dynDNS or Dynu with several dynamic domains and via specific interface(s)...
:local ddns do={
	:local dynhost
	:local dynurlv

	:if (([:len $provider]=0) or ([:len $host]=0) or ([:len $username]=0) or ([:len $password]=0)) do={
		:error "missing parameters"
	}

	:if ($provider="dynu") do={
		:set dynhost "api.dynu.com"
		:set dynurlv "/nic/update?hostname=$host"
	}
	:if ($provider="dyndns") do={
		:set dynhost "members.dyndns.org"
		:set dynurlv "/nic/update?hostname=$host&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
	}
	:set dynhost [:resolve $dynhost];

   :local wanGateway do={
    	:if ([:len [/ip dhcp-client find where interface=[:tostr $1]]]>0) do={
    		:return [/ip dhcp-client get [find interface=[:tostr $1]] gateway]
    	} else={
    		:return [$1]
    	}
    }

	# All return codes
	:global resultcodes {
		good="Update successful";
    	nochg="Update not needed, WARNING: repeated attempts may cause you to be blocked.";
    	badauth="The username and password pair do not match a real user.";
    	notfqdn="The hostname specified is not a fully-qualified domain name.";
    	nohost="The hostname specified does not exist in this user account.";
    	numhost="Too many hosts (more than 20) specified in an update.";
    	abuse="The hostname specified is blocked for update abuse.";
    	badagent="The user agent was not sent or HTTP method is not permitted.";
    	dnserr="DNS error encountered.";
    	911="There is a problem or scheduled maintenance on our side."
	}

	:log info ("updating dynamic dns '$host' from '$provider' ...");
	:if (([:len [/interface find name=$interface]]>0) and ([/interface get value-name=disabled $interface]=no)) do={
		/ip route add distance=1 gateway=[$wanGateway $interface] dst-address=$dynhost comment="updating '$host' via '$interface'"
		:delay 800ms;
	}
	/tool fetch address=$dynhost src-path=$dynurlv mode=http user=$username password=$password dst-path=("$provider.$host")

	:delay 2s
	:if ([:len [/file find name=("$provider.$host")]]>0) do={
		:local result [/file get value-name=contents [/file find name=("$provider.$host")]]
		# Separate return code from IP address
		:for i from=0 to=( [:len $result] - 1) do={
			:if ( [:pick $result $i] = " ") do={
				:set result [:pick $result 0 $i]
			}
		}
		:foreach resultcode,desc in=$resultcodes do={
			:if ($result=$resultcode) do={
				:log warning ("$provider ($host): $desc")
			}
		}
	} else={
		:log error ("Update dynamic dns '".$host."' failed...");
	}
	/file remove [/file find name=("$provider.$host")]
	/ip route remove [/ip route find where comment="updating '$host' via '$interface'"]
}

:do {
	## Configuration file
	:local fconfig [:parse [/system script get "ddns.cfg" source]]
	:local cfg [$fconfig]
	:local HOSTS ($cfg->"hosts")
	:local ACCOUNTS ($cfg->"accounts")
	## Foreach HOSTS
	:foreach Host in=[:toarray $HOSTS] do={
		:local wan
		:local dynprov
		:local dynhost
		:local dynuser
		:local dynpass
		:if ([:len [:pick $Host (-1) ([:find $Host "|"])]]>0) do={
			:set wan [:pick $Host 0 ([:find $Host "|"])]
			:set dynprov [:pick $Host ([:find $Host "|"]+1) [:find $Host "@"]]
			:set dynhost [:pick $Host ([:find $Host "@"]+1) [:len $Host]]
		} else={
			:set dynprov [:pick $Host 0 [:find $Host "@"]]
			:set dynhost [:pick $Host ([:find $Host "@"]+1) [:len $Host]]
		}
		:if ([:len [:pick $ACCOUNTS (-1) ([:find $ACCOUNTS "|"])]]>0) do={
			:foreach account in=[:toarray $ACCOUNTS] do={
				:if ([:pick $account 0 [:find $account "|"]]=$dynprov) do={
					:set dynuser [:pick $account ([:find $account "|"]+1) [:find $account "@"]]
					:set dynpass [:pick $account ([:find $account "@"]+1) [:len $account]]
				}
			}
		} else={
			:set dynuser [:pick $ACCOUNTS 0 [:find $ACCOUNTS "@"]]
			:set dynpass [:pick $ACCOUNTS ([:find $ACCOUNTS "@"]+1) [:len $ACCOUNTS]]
		}
		:if ((([:len $interface]=0) and ([:len $wan]=0)) or ($wan=$interface)) do={
			$ddns provider=$dynprov host=$dynhost username=$dynuser password=$dynpass interface=$wan
		}
	}
}
Include configuration file ddns.cfg
:local config {
	"hosts"="dynu@YOURDOMAIN,dyndns@YOURDOMAIN,INTERFACE|dynu@YOURDOMAIN";
	"accounts"="dyndns|USERNAME@PASSWORD,dynu|USERNAME@PASSWORD";
	"storage"="";
}
return $config
If you using PPPOE or any PPP connection you can add script into PPP profile while connected and do like this for automatic update:
/interface pppoe-client monitor INTERFACE once do={
	:local uptime ([:tonum [:pick [:tostr $uptime] 0 2]]*60*60+[:tonum [:pick [:tostr $uptime] 3 5]]*60+[:tonum [:pick [:tostr $uptime] 6 8]])
}
:if ($uptime<3) do={
	/system script run ddns
}
My script post in here for any questions: viewtopic.php?f=9&t=130992&p=643242&hilit=dynu#p643242

Who is online

Users browsing this forum: No registered users and 24 guests