Community discussions

MikroTik App
 
chryoung
just joined
Topic Author
Posts: 11
Joined: Sun Dec 18, 2016 8:31 pm

Dynu.com script for dynamic DNS

Sun Dec 18, 2016 8:36 pm

Hi,

My first post here and I'm also new to Router OS. I'm using Dynu for dynamic DNS so that I can remote to devices on my network which uses a dynamic IP for the WAN. Dynu provides this script but when I load it there are errors. Maybe someone here can see obvious problems with the syntax? Thanks in advance for your help.

/system script
add name=Dynu
policy=read,write,test
source=":global ddnsuser your_Dynu_username
:global ddnspass "your_Dynu_password"
:global theinterface "WAN_Interface_Name"
:global ddnshost "your_Dynu_hostname"
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynuDDNS: 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 ("DynuDDNS: IP-Dynu = $ipddns")
:log info ("DynuDDNS: IP-Fresh = $ipfresh")
:log info "DynuDDNS: Update IP needed, Sending UPDATE...!"
:global str "/nic/update?hostname=$ddnshost&myip=$ipfresh"
/tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost)
:delay 1
:global str [/file find name="Dynu.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynuDDNS: IP updated to $ipfresh!"
} else={
:log info "DynuDDNS: dont need changes";
} }
 
Matellito
just joined
Posts: 4
Joined: Fri Sep 14, 2012 5:02 am

Re: Dynu.com script for dynamic DNS

Sat Dec 31, 2016 12:59 am

Change your data
Configure in scheduler every 30 minutes
:global ddnsuser "Usernam Dynu.com"
:global ddnspass "Password Dynu.com"
:global theinterface "Interface"
:global ddnshost "domain.dynu.com"
:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("dynu: 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 ("dynu: IP-dynu = $ipddns")
:log info ("dynu: IP-Fresh = $ipfresh")
:log info "dynu: Update IP needed, Sending UPDATE...!"
:global str "/nic/update?hostname=$ddnshost&myip=$ipfresh"
/tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost)
:delay 1
:global str [/file find name="Dynu.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "dynu: IP updated to $ipfresh!"
} else={
:log info "dynu: dont need changes";
}
}
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1490
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Dynu.com script for dynamic DNS

Tue Feb 12, 2019 5:57 am

I know this is a two year old thread, but I'm in the same boat. I added info log entries all over the place and remarked every line and ran the script. Obviously it ran fine with just the log full of the log entries. I then started at the top and removed the remarks one line at a time until it bombed. In this configuration, I get the "Starting Dynu script", "Globals set", and "line 1" log entries and then nothing. Yes, the interface name is correct (in fact, I copied it directly from last night's .rsc file). Doing this on a model = RouterBOARD 750 r2 running RouterOS 6.43.2
:log info "Starting Dynu script"
:global ddnsuser "user name redacted"
:global ddnspass "password redacted"
:global theinterface "E1-p10_DSL_Internet"
:global ddnshost "The domain I'm trying to apply this to"
:log info "Globals set"
:global ipddns [:resolve $ddnshost];
:log info "line 1"
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:log info "line 2"
# :if ([ :typeof $ipfresh ] = nil ) do={
:log info "line 3"
# :log info ("DynuDDNS: No IP address on $theinterface .")
:log info "line 4"
# } else={
:log info "line 5"
# :for i from=( [:len $ipfresh] - 1) to=0 do={
:log info "line 6"
# :if ( [:pick $ipfresh $i] = "/") do={
:log info "line 7"
# :set ipfresh [:pick $ipfresh 0 $i];
:log info "line 8"
# }
:log info "line 9"
# }
:log info "line 10"
# :if ($ipddns != $ipfresh) do={
:log info "line 11"
# :log info ("DynuDDNS: IP-Dynu = $ipddns")
:log info "line 12"
# :log info ("DynuDDNS: IP-Fresh = $ipfresh")
:log info "line 13"
# :log info "DynuDDNS: Update IP needed, Sending UPDATE...!"
:log info "line 14"
# :global str "/nic/update?hostname=$ddnshost&myip=$ipfresh"
:log info "line 15"
# /tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=# ("/Dynu.".$ddnshost)
:log info "line 16"
# :delay 1
:log info "line 17"
# :global str [/file find name="Dynu.$ddnshost"];
:log info "line 18"
# /file remove $str
:log info "line 19"
# :global ipddns $ipfresh
:log info "line 20"
# :log info "DynuDDNS: IP updated to $ipfresh!"
:log info "line 21"
# } else={
:log info "line 22"
# :log info "DynuDDNS: dont need changes";
:log info "line 23"
# } }"
Any ideas? I fully admit that I know VERY little about scripting...
 
HzMeister
Frequent Visitor
Frequent Visitor
Posts: 73
Joined: Sun Jan 28, 2018 9:48 pm

Re: Dynu.com script for dynamic DNS

Tue Feb 12, 2019 10:13 am

I just add the mikrotik ddns to "dns records" in dynu. No scripting necessary.
 
Kampfwurst
Member Candidate
Member Candidate
Posts: 107
Joined: Mon Mar 24, 2014 2:53 pm

Re: Dynu.com script for dynamic DNS

Fri Jul 05, 2019 9:12 am

I just add the mikrotik ddns to "dns records" in dynu. No scripting necessary.
can you explain it?
 
Mefix
just joined
Posts: 1
Joined: Fri Jan 24, 2020 10:24 pm

Re: Dynu.com script for dynamic DNS

Fri Jan 24, 2020 10:29 pm

I just add the mikrotik ddns to "dns records" in dynu. No scripting necessary.
can you explain it?
Sorry for necroposting, need in Record DNS add address name NULL(not enter), Type CNAME ,Hostname: DDNS Name for Cloud, and disable name type A.

https://yadi.sk/i/ezOMuefy799YlQ
Last edited by Mefix on Fri Jan 24, 2020 10:30 pm, edited 1 time in total.
 
yoosmel
just joined
Posts: 1
Joined: Thu Aug 20, 2020 9:11 pm

Re: Dynu.com script for dynamic DNS

Thu Aug 20, 2020 11:17 pm

Hello,
This works when the cloud is behind nat. It does not work for me
 
KCameron
just joined
Posts: 1
Joined: Thu Dec 23, 2021 8:31 pm

Re: Dynu.com script for dynamic DNS

Thu Dec 23, 2021 8:45 pm

I found this thread when googling how to get my system to work with dynu. It helped me to understand what to do.
However, I don't think it's necessary for the script to keep track of IP address.

This script works well for me and seems much simpler:
/tool fetch url="https://api.dynu.com/nic/update\?userna ... mypassword"

I just schedule this to run every hour. Seems to work perfectly.
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: Dynu.com script for dynamic DNS

Fri Dec 24, 2021 9:34 pm

Sure it works, but your DDNS provider may be less excited, because you're doing useless updates that don't really change anything, and putting extra load on their server. And obviously, you're not going to overload it yourself, but if everyone did it this way, and not everyone would see once an hour as enough, ... you get the idea.
 
User avatar
Shahid
newbie
Posts: 25
Joined: Sat Nov 05, 2016 3:31 am
Location: Multan, Pakistan
Contact:

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 1:09 am

Latest Code Working
 /tool fetch mode=http url="http://api.ipify.org" src-path="" dst-path=/dyn.html
:local currentIP [/file get dyn.html contents]
:log warning "Public IP Detected $currentIP"
######################################################
 
:global ddnsuser "username"
:global ddnspass "password"
:global ddnshost "host.mywire.org"
:global ipddns [:resolve $ddnshost];
:log warning "Current DNS $ipddns"
/file/remove dyn.html

:if ($ipddns != $currentIP) do={
:log warning ("Updating IP = $currentIP")
:global str "/nic/update?username=$ddnsuser&password=$ddnspass&hostname=$ddnshost&myip=$currentIP"
/tool fetch address=api.dynu.com src-path=$str mode=https dst-path=("/Dynu.".$ddnshost)
:delay 1
:global str [/file find name="Dynu.$ddnshost"];
/file remove $str
:global ipddns $currentIP
:log info "DynuDDNS: IP updated to $currentIP!"
} else={
:log info "No Need to change, IP Already Updated";
} }
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 2:12 am

Better do some cleaning up on that mess, including removing the useless logging...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 2:13 am

:local ddnsuser  "username"
:local ddnspass  "password"
:local ddnshost  "host.mywire.org"

:local currentIP ([/tool fetch url="http://api.ipify.org" as-value output=user]->"data")
:local dnsIP     [:resolve $ddnshost]
:if ($currentIP != $dnsIP) do={
    :local update "https://api.dynu.com/nic/update?username=$ddnsuser&password=$ddnspass&hostname=$ddnshost&myip=$currentIP"
    /tool fetch url=$update keep-result=no
    :log info "DYNU $ddnshost updated: old IP was $dnsIP and new IP is $currentIP"
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 9:45 am

@Shahid

Do use global variable in the script only if you intend to use the variable in other script or for use at a later time. Use local variable instead.
 
User avatar
Shahid
newbie
Posts: 25
Joined: Sat Nov 05, 2016 3:31 am
Location: Multan, Pakistan
Contact:

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 9:51 am

@Shahid

Do use global variable in the script only if you intend to use the variable in other script or for use at a later time. Use local variable instead.
Sure. Thanks for suggestions.
 
User avatar
Shahid
newbie
Posts: 25
Joined: Sat Nov 05, 2016 3:31 am
Location: Multan, Pakistan
Contact:

Re: Dynu.com script for dynamic DNS

Sun Oct 09, 2022 9:53 am

:local ddnsuser  "username"
:local ddnspass  "password"
:local ddnshost  "host.mywire.org"

:local currentIP ([/tool fetch url="http://api.ipify.org" as-value output=user]->"data")
:local dnsIP     [:resolve $ddnshost]
:if ($currentIP != $dnsIP) do={
    :local update "https://api.dynu.com/nic/update?username=$ddnsuser&password=$ddnspass&hostname=$ddnshost&myip=$currentIP"
    /tool fetch url=$update keep-result=no
    :log info "DYNU $ddnshost updated: old IP was $dnsIP and new IP is $currentIP"
}
Good
I don't know much about scripting. I just got that working so i posted that here. Thanks for the improvement.
 
MDAcosta
just joined
Posts: 2
Joined: Wed Mar 22, 2023 5:20 pm

Re: Dynu.com script for dynamic DNS

Sat Mar 25, 2023 7:48 pm

Why is that no one keeps track of the current dynamic IPv6 from the router? Is that because the obtained IPv6 is a suffixed address and not a complete one as you can get from a peripheral?
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1490
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Dynu.com script for dynamic DNS

Sat Mar 25, 2023 8:03 pm

Why is that no one keeps track of the current dynamic IPv6 from the router? Is that because the obtained IPv6 is a suffixed address and not a complete one as you can get from a peripheral?
Very simple answer. Not using IPv6...

Who is online

Users browsing this forum: Google [Bot], rextended and 33 guests