dynDNS Update Script

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
  }
}
  1. 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

Thank you…
This is working great !!!

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!

these are the only variables.
what happens if you run the script manually: /system script run dynDNS
have you set the scheduler?

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…

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

ok!

my scheduler line is :

/system script run dynDNS \r\n

let’s see if it’s working…

It’s not working…

Scheduler counting but the IP is not changing…

have you set Policy correctly?

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”

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.

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

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

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 :smiley:

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

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 :confused:
but you said it doesn’t support address and it said ignoring username and password!!
is it a Bug in MT manual? :slight_smile:

the http mode won’t support user authentification in your version.
your fetch just can auth over ftp

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:

sry, not sure for that

Ok thanks for replying…
I’ll try to downgrade the advanced-tools-3.28.npk :sunglasses: