Community discussions

MikroTik App
 
nicolap
just joined
Topic Author
Posts: 12
Joined: Mon Sep 09, 2019 12:16 am

[solved] dyndns script strangeness

Sun Nov 20, 2022 4:01 pm

Hi all,
I've two router
A) RB962UiGS-5HacT2HnT - Hap ac - ROS 7.5
B) RB760iGS - Hex S - ROS 7.5
The configurations of both are different but very simple and both run this script to update dyndns:
#uses api.ipfy.org because can be polled very often

#test account to not be blocked!
  :set username "test"
  :set password "test"
  :set hostname "test4.customtest.dyndns.org"

# Set CONFIG
  :local dyndnsForce false
  :local previousIP [resolve $hostname]
  :local useIpify true

# 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

:local currentIP

:if ($useIpify = true) do={
  :set currentIP  ([/tool fetch url="http://api.ipify.org/" as-value output=user]->"data")

} else={
  :local resultArray [/tool fetch url="http://checkip.dyndns.org/" as-value output=user]
  :local result ($resultArray->"data")

  # parse the current IP result
  :local startLoc [:find $result "ddress: " -1]
  :set startLoc ($startLoc + 8)
  :local endLoc [:find $result "</body>" -1]
  :local currentIP [:pick $result $startLoc $endLoc]
}

# 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 "DynDNS: currentIP = _$currentIP_ - previous IP = _$previousIP_"
    :local UpdResult [/tool fetch url=("https://$username:$password@members.dyndns.org/v3/update?hostname=" \ 
      . $hostname . "&myip=" . $currentIP) as-value output=user];
    :log info ("DynDNS: " . $UpdResult->"data")
  } else={
    #:log info ("DynDNS: No dyndns update needed")
  }
The script runs every minute.
The router A shows every time in the log the message
DynDNS: currentIP = _12.34.249.206_ - previous IP = _12.34.249.206_
The router B only a cople of time every week.

The strange thing is that every time the two IPs are the same!
So or there is a bug or I'm missing something. And the latter is more probable...
Any thoughts?
Thanks
Nicola
Last edited by nicolap on Mon Nov 21, 2022 6:26 pm, edited 1 time in total.
 
nicolap
just joined
Topic Author
Posts: 12
Joined: Mon Sep 09, 2019 12:16 am

Re: dyndns script strangeness

Mon Nov 21, 2022 6:25 pm

I found the problems:
1) in one of the router the hostname was also in the static dns of ROS (hairpin...) so every time the new IP was different (the old was set manually the first time).
In the resolve command I was not forcing a dns server to use, now i changed to
  :local previousIP [resolve $hostname server=208.67.222.222]
2) the command to log the IPs was AFTER :set previousIP $currentIP :( :(
I swapped the two command and now it works.

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 72 guests