Community discussions

MikroTik App
 
TedjeVanEs
just joined
Topic Author
Posts: 20
Joined: Mon Jan 26, 2015 10:14 pm
Location: Aruba

DYNDNS update script not working

Wed Sep 23, 2015 8:34 pm

I have a script, but it does not seem to work anymore.
Not even a single line in the logs. When I make a small test script that does nothing but :log info "test msg", it does appear in the logs.
Any advice how I can debug this and get it to work again? Has scripting changed in one of the updates? How can some error in the script stop it from executing completely??

[edit]: the problem seems to be in the last piece of code, where it checks for ip format and compares the old and new ip addresses.

# HomingBeacon Main Dynamic DNS Update Script
# Written by Sam Norris, ChangeIP.com
# 20100728 Tested on RouterOS 4.9
# 20110511 Tested on RouterOS 5.2

# Set your specific ChangeIP.com preferences here.
:global ddnsuser "*****"
:global ddnspass "***************"
:global ddnshost "example.ddns.info"
# Change ddnsport to 8245 to bypass proxy.
:local ddnsport 8245

# Do not edit anything below this line.  You have been warned.
# Abusive updates to the system will cause firewall blocks.

# Please be considerate and
# do not let this script run more than once per 3-5 minutes.

:log info "DDNS: Starting."

# Initialize checkpoint
:global ddnscheckpoint
:if ([:typeof $ddnscheckpoint] = "time") do={
	:log info ("DDNS: Last check was " . ([/system clock get time] - $ddnscheckpoint))
} else={
	:log info "DDNS: Cannot determine checkpoint, set now."
	:global ddnscheckpoint ( [/system clock get time] - 1d )
}

# Get the current IP
:if ([/system clock get time] - $ddnscheckpoint > [:totime 180s] || [/system clock get time] - $ddnscheckpoint < [:totime 0s]) do={
   :log info "DDNS: Performing remote IP detection."
   /tool fetch address="ip.changeip.com" host="ip.changeip.com" src-path=("/?" . [/int eth get 0 mac-address ]) dst-path="ip.changeip.com.txt" mode=http port=$ddnsport
   :global ddnscheckpoint [/system clock get time]
} else={
   :log info "DDNS: Please be considerate and wait a few seconds longer."
   :break
}

# Parse the IP address received from fetch script.
	:global ddnslastip
	:local html [/file get "ip.changeip.com.txt" contents]
	:local ddnsip [:pick $html ([:find $html "<!--IPADDR="] + 11) [:find $html "-->"] ]

# Is it a valid IP and is it different than the last one?
	:if ([:typeof [:toip $ddnsip]] = "ip" AND $ddnsip != $ddnslastip ) do={
		:log warning"DDNS: Sending UPDATE with $ddnsip"
		:log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ]
		:global ddnslastip $ddnsip
	} else={
		:log info "DDNS: No update required."
	}
}
 
TedjeVanEs
just joined
Topic Author
Posts: 20
Joined: Mon Jan 26, 2015 10:14 pm
Location: Aruba

Re: DYNDNS update script not working

Fri Sep 25, 2015 1:01 am

anyone?
 
dadoremix
Member Candidate
Member Candidate
Posts: 133
Joined: Sat May 14, 2011 11:31 am

DYNDNS update script not working

Fri Sep 25, 2015 2:12 am

Find other topic or my posts, i posted working script for dyndns
 
TedjeVanEs
just joined
Topic Author
Posts: 20
Joined: Mon Jan 26, 2015 10:14 pm
Location: Aruba

Re: DYNDNS update script not working

Sat Sep 26, 2015 11:37 pm

I have searched these forums extensively, and tried many different scripts posted here. But not a single one seems to work.
The previous one worked perfectly for more than 6 months. So I am trying to understand why it broke, and what to do to fix it.

My theory is something changed in the way scripts are interpreted and executed. I narrowed it down to the last 10 lines of code. The thing that baffles me most is: how is it possible that a syntax error (?) at the end of the script, also prevents the first commands from being executed.
Please help me.
 
dadoremix
Member Candidate
Member Candidate
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: DYNDNS update script not working

Sun Sep 27, 2015 1:20 am

# 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 type here
:local password type here pass
:local hostname dxxxxx.dyndns.tv
:local emailAddress dxxxx@mail

: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")
}


that script i use on 6.33.rc15
 
TedjeVanEs
just joined
Topic Author
Posts: 20
Joined: Mon Jan 26, 2015 10:14 pm
Location: Aruba

Re: DYNDNS update script not working

Sun Sep 27, 2015 6:42 pm

Tnx for that script and confirming it works on your router.
I will try to adapt it for my dynamic DNS provider I use ChangIP instead of DynDNS.com

Who is online

Users browsing this forum: mszru and 54 guests