Page 1 of 1

DNSdynamic script for RouterOS v6

Posted: Fri Jun 15, 2018 6:23 pm
by Pietist
I want to use script to inform DNSdynamic about my ip.
https://www.dnsdynamic.org/compatibility.php
I has changed example for No-IP and composed this script for DNSdynamic:
# DNSdynamic update
#User account info
:local dnsdynamicuser "amuliar@protonmail.ch"
:local dnsdynamicpass "YL6a1##DynaPietist"
:local dnsdynamichost "pietist.ssh22.net"

# Change to the name of interface that gets the dynamic IP address
:local inetinterface "pppoe-out-langate"

:global previousIP

:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interfacea
   :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]

# Strip the net mask off the IP address
   :for i from=( [:len $currentIP] - 1) to=0 do={
       :if ( [:pick $currentIP $i] = "/") do={ 
           :set currentIP [:pick $currentIP 0 $i]
       } 
   }

   :if ($currentIP != $previousIP) do={
       :log info "IP: Current IP $currentIP is not equal to previous IP, update needed"
       :set previousIP $currentIP

# The update dnsdynamic URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
       :local url "https://www.dnsdynamic.org/api/\3Fhostname=$dnsdynamichost&myip=$currentIP"
       :log info "dnsdynamic: $url"
       :local dnsdynamichostarray
       :set dnsdynamichostarray [:toarray $dnsdynamichost]
       :foreach host in=$dnsdynamichostarray do={
           :log info "dnsdynamic: Sending update for $host"
           /tool fetch url=$url user=$dnsdynamicuser password=$dnsdynamicpass mode=https dst-path=("dnsdynamic_ddns_update-" . $host . ".txt")
           :log info "dnsdynamic: Host $host updated on dnsdynamic with IP $currentIP"
       }
   }  else={
       :log info "IP: Previous IP $previousIP is equal to current IP, no update needed"
   }
} else={
   :log info "IP: $inetinterface is not currently running, so therefore will not update."
}
I suppose, something is not correct here because "dnsdynamic: Host $host updated on dnsdynamic with IP $currentIP" doesn't appear in log.
Could you please help me to figure out what is incorrect?

RouterOS v6.40.4

Re: DNSdynamic script for RouterOS v6

Posted: Tue Jul 17, 2018 7:28 pm
by MSandoval
if you want you can use the DNS options that the mikrotik brings.

IP > Cloud - DNS Enable

And then use the DNS name that give you. I hope can help you.

And very important. I recommend you delete your information about your loggin in the dnsdynamic.org. because any can loggin and use that information against you.

Image
http://subirimagen.me/uploads/20180717112726.jpg

Re: DNSdynamic script for RouterOS v6

Posted: Tue Jul 17, 2018 7:38 pm
by dasiu
OMG, MSandoval! I didn't notice, that he included his real login information in the script! Thanks for pointing it out loud, so all of us now can notice it! :)

Re: DNSdynamic script for RouterOS v6

Posted: Tue Jul 17, 2018 11:40 pm
by gotsprings
I have resorted to using a script that writes all the user/pass/hostname to global variables at start up. Then my dyndns updater calls that info... so i don't make that mistake right there.