Community discussions

MikroTik App
 
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: 19100
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 27 guests