DynDNS script error with Mikrotik

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Hi guys,

Ok im trying to load the following script but I seem to get and error on my "/tool fetch" line.

The code:
Code:
/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."
  }

}
}

I did edit the variables with my details so I know about that.

Now the error:
Code:
{{{...     /tool fetch keep-result=no url="http://$ddnsuser:$ddnspass@dyndns.com
/nic/update\?hostname=$ddnshost"
bad argument name url (line 37 column 32)

Help please! The updater on my pc doesn't update quick enough
 

Anthro

Expert Member
Joined
Jun 13, 2006
Messages
3,560
Here's my script I used on my routerboard
Just note the :set hostname "xxx" values for your variables
Code:
# Set needed variables
:local username "YourUsername"
:local password "YourPassword"
:local hostname "nohostset"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname "ozone.dnsalias.net"
}
:if ($systemname  = "Site2" ) do= {
:set hostname "moonguard.dnsalias.net"
}
:if ($systemname  = "Site3" ) do= {
:set hostname "xbearer.dnsalias.net"
}

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

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
+1

Seems to be working like a dream for now.

Thanks a bunch :D
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Sorry to bug again.

Seems I was mistaken. Script is not updating on the dyndns site.

Changed login so that IP would change, ran the script.. all the info reported correctly but logging onto the dyndns site, my IP has not changed.

Edit: I'm trying to add the follwoing code after the "so-called" update for debugging purposes but after insertion script won't run.

Code:
# Check if UPDATE is successful

:local dyndnsip [:resolve "toedy.homeip.net" ]
:local newIP [/file get dyndns.checkip.html contents]
:if ($newIP != $dyndnsip) do={
:log info ("UPDATE was unsuccessful")
}else={
:log info ("UPDATE was successful")
}
 
Last edited:
Top