Community discussions

 
NevOZ
just joined
Topic Author
Posts: 7
Joined: Thu Jul 21, 2011 2:15 am

DuckDNS Update Script (free DynDNS alternative)

Fri Apr 18, 2014 3:10 am

Hello All,

As many of you know, DynDNS will cease to have free dynamic DNS services within a month's time.

As a result, I will be using one of the alternative free services instead - DuckDNS ( https://duckdns.org/ ) , and thought I'd share my script.

This script runs differently to almost all other Mikrotik dynamic DNS update scripts I have found on the Net. The usual method is to have the script run at intervals. Whereas my script runs all the time, monitors the WAN connection, and detects if the IP address changes. Not saying this is a better way, it is just the way I have done it.
So therefore, when setting it up in the Mikrotik scheduler, set it to run at startup only.

All you need to change in the script below is the "exampledomain" and the token.

Hope it's handy for someone.

Nev

ros code

/ interface pppoe-client {
	:global ExternalIP
	:local clientip
	:local clientstatus
	:while (1 < 2) do={
		monitor pppoe-out1 once do={:set clientip $"local-address"; :set clientstatus $status}
		:if ($clientstatus="connected" and $ExternalIP!=$clientip) do={
			:delay 1  
			:log info "UpdateDuckDNS: IP change detected - $ExternalIP to $clientip. Updating Duck DNS."
			/tool fetch mode=https url="https://www.duckdns.org/update?domains= ... =$clientip" dst-path=duckdns.txt;
			:delay 1
			:local result [/file get duckdns.txt contents]
			:log info "UpdateDuckDNS: Duck DNS update result: $result";
			:set ExternalIP $clientip
		}
		:delay 5
		}
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2946
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: DuckDNS Update Script (free DynDNS alternative)

Fri Apr 18, 2014 6:15 am

LogMeIn & DynDNS : two example of business.

Do not help anyone to make and grow free service, when you have debugged "all the problem" and the program is near vital to you, the program end Free support, on 30 days... or 7 days only...

Very ransom example....

There are also many service like this two on the years...

Do not base your works on free product,
not be blind on Open source project. Not all bug discovered, because free code, are reported...
I'm Italian, not English. Sorry for my imperfect grammar.
 
NevOZ
just joined
Topic Author
Posts: 7
Joined: Thu Jul 21, 2011 2:15 am

Re: DuckDNS Update Script (free DynDNS alternative)

Fri Apr 18, 2014 7:16 am

...when you have debugged "all the problem" and the program is near vital to you...
7 days I agree is too soon to allow users to transition, but if the service is "vital", then it is probably worth paying for. Just remember that what they are providing does cost them money.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2946
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: DuckDNS Update Script (free DynDNS alternative)

Fri Apr 18, 2014 10:46 am

...when you have debugged "all the problem" and the program is near vital to you...
7 days I agree is too soon to allow users to transition, but if the service is "vital", then it is probably worth paying for. Just remember that what they are providing does cost them money.
Yes, ok, cost money, but is no reasonable only 7 days for migration of 40 machine.
This is a ransom....
I'm Italian, not English. Sorry for my imperfect grammar.
 
NevOZ
just joined
Topic Author
Posts: 7
Joined: Thu Jul 21, 2011 2:15 am

Re: DuckDNS Update Script (free DynDNS alternative)

Sat Apr 19, 2014 2:44 am

40 machines? If you are saying there are 40 different hostnames then you are violating the DynDNS free account terms anyway. You are only permitted to have 1 free account, and each account only allows 1 or 2 hostnames I believe.

Yes, ok, cost money, but is no reasonable only 7 days for migration of 40 machine.
This is a ransom....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2946
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: DuckDNS Update Script (free DynDNS alternative)

Sat Apr 19, 2014 10:08 am

Yes, ok, cost money, but is no reasonable only 7 days for migration of 40 machine.
This is a ransom....
40 machines? If you are saying there are 40 different hostnames then you are violating the DynDNS free account terms anyway. You are only permitted to have 1 free account, and each account only allows 1 or 2 hostnames I believe.
I'm talk about LogMeIn, not DynDNS.
I'm Italian, not English. Sorry for my imperfect grammar.
 
User avatar
THG
Member
Member
Posts: 472
Joined: Thu Oct 15, 2009 1:05 am

Re: DuckDNS Update Script (free DynDNS alternative)

Sun Apr 20, 2014 10:20 pm

This script runs differently to almost all other Mikrotik dynamic DNS update scripts I have found on the Net. The usual method is to have the script run at intervals. Whereas my script runs all the time, monitors the WAN connection, and detects if the IP address changes. Not saying this is a better way, it is just the way I have done it.
So therefore, when setting it up in the Mikrotik scheduler, set it to run at startup only.
This script will only work with a PPPoE connection. If you have the energy, please make a script that works with ethernet.

Thanks
 
NevOZ
just joined
Topic Author
Posts: 7
Joined: Thu Jul 21, 2011 2:15 am

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Apr 21, 2014 1:20 am

This script will only work with a PPPoE connection. If you have the energy, please make a script that works with ethernet.

Thanks
I haven't tested this as I don't run a direct WAN connection, but you could try:

1. removing lines 1,3 and 4
2. change line 6 to :

:local clientip [/ip address get [find interface="ether2-master-local"] address]

(obviously change "ether2-master-local" to appropriate interface)

3. change line 7 to:

:if ($ExternalIP!=$clientip) do={


.. see how you go.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2946
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Apr 21, 2014 3:43 am

How to...

On the follow sript replace MATRIX with ethernet interface or bridge (probably obtaining IP by DHCP client) you want to use as source IP for DuckDNS.

1) Obtain the ip of ethernet interface, the second instruction remove /xx if present:
:global actualIP value=[/ip address get [find where interface=MATRIX] value-name=address];
:global actualIP value=[:pick $actualIP -1 [:find $actualIP "/" -1] ];
2) Read if the previous IP is different from the actual. IT ALSO REMEMBER THE IP BETWEEN REBOOTS.
First part check for file existance, the last line set previousIP variables. The delay are inserted to do time to system to write the file.
:if ([:len [/file find where name=ipstore.txt]] < 1 ) do={
 /file print file=ipstore.txt where name=ipstore.txt;
 /delay delay-time=2;
 /file set ipstore.txt contents="0.0.0.0";
};
:global previousIP value=[/file get [find where name=ipstore.txt ] value-name=contents];
3) If previous IP are different to new, update DuckDNS, and save permanently new value on files to mantain the info througt reboot:
:if ($previousIP != $actualIP) do={
 /tool fetch mode=https keep-result=yes dst-path=duckdns-result.txt address=[:resolve www.duckdns.org] port=443 host=www.duckdns.org src-path=("/update?domains=ww.matrix.it&token=65843E27-A491-429F-84A0-30A947E20F92&ip=".$actualIP);
 /delay delay-time=5;
 :global lastChange value=[/file get [find where name=duckdns-result.txt ] value-name=contents];
 :global previousIP value=$actualIP;
 /file set ipstore.txt contents=$actualIP;
};
REMEMBER TO ADD \ BEFORE ? (on "/update?doma....") IF YOU WANT TRY IT ON TERMINAL.
DO NOT PUT \ BEFORE ? INSIDE A SCRIPT.


The logging facility is added in complete version.

This is the complete script, without the interruption to explain what's happen:
:global actualIP value=[/ip address get [find where interface=MATRIX] value-name=address];
:global actualIP value=[:pick $actualIP -1 [:find $actualIP "/" -1] ];
:if ([:len [/file find where name=ipstore.txt]] < 1 ) do={
 /file print file=ipstore.txt where name=ipstore.txt;
 /delay delay-time=2;
 /file set ipstore.txt contents="0.0.0.0";
};
:global previousIP value=[/file get [find where name=ipstore.txt ] value-name=contents];
:if ($previousIP != $actualIP) do={
 :log info message=("Try to Update DuckDNS with actual IP ".$actualIP." -  Previous IP are ".$previousIP);
 /tool fetch mode=https keep-result=yes dst-path=duckdns-result.txt address=[:resolve www.duckdns.org] port=443 host=www.duckdns.org src-path=("/update?domains=ww.matrix.it&token=65843E27-A491-429F-84A0-30A947E20F92&ip=".$actualIP);
 /delay delay-time=5;
 :global lastChange value=[/file get [find where name=duckdns-result.txt ] value-name=contents];
 :global previousIP value=$actualIP;
 /file set ipstore.txt contents=$actualIP;
 :if ($lastChange = "OK") do={:log warning message=("DuckDNS update successfull with IP ".$actualIP);};
 :if ($lastChange = "KO") do={:log error message=("Fail to update DuckDNS with new IP ".$actualIP);};
};



Remember to add Karma if you find this info useful...
Thanks.
.
Last edited by rextended on Tue Apr 22, 2014 12:05 pm, edited 1 time in total.
I'm Italian, not English. Sorry for my imperfect grammar.
 
User avatar
THG
Member
Member
Posts: 472
Joined: Thu Oct 15, 2009 1:05 am

Re: DuckDNS Update Script (free DynDNS alternative)

Tue Apr 22, 2014 3:03 am

Thanks to both of you, I will test this when I have time.
 
User avatar
THG
Member
Member
Posts: 472
Joined: Thu Oct 15, 2009 1:05 am

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Dec 29, 2014 2:29 am

The logging facility is added in complete version.

This is the complete script, without the interruption to explain what's happen:
Thanks, the script works very well.
 
fbsdmon
newbie
Posts: 29
Joined: Thu Dec 29, 2011 11:37 pm

Re: DuckDNS Update Script (free DynDNS alternative)

Sat Mar 02, 2019 12:37 pm

@rextended
The script works only when executed from the MikroTik terminal for me.
It does not work if I click on "run" form the script menu or if I run it via the scheduler. It throws: "could not run script DuckDNS: not enough permissions". i tried giving all permissions to the script, but I still get the same error. I create and run the script with the same user that I use to execute the script via terminal.

To reproduce this:
- Delete the "actualIP", "lastChange" and "previousIP" global variables from System->Scripts->Environment
- Delete the "ipstore.txt" and "duckdns-result.txt" files
- Run the script from System->Scripts->Scripts (select and click "run script")

Any ideas what might be the problem?
As said, I am running as the same user with all permissions granted. I run routeros-mmips v6.44
 
badwithnetworking
just joined
Posts: 8
Joined: Mon Jul 29, 2019 9:20 am

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Jul 29, 2019 3:56 pm

This is the complete script, without the interruption to explain what's happen:
:global actualIP value=[/ip address get [find where interface=MATRIX] value-name=address];
:global actualIP value=[:pick $actualIP -1 [:find $actualIP "/" -1] ];
:if ([:len [/file find where name=ipstore.txt]] < 1 ) do={
 /file print file=ipstore.txt where name=ipstore.txt;
 /delay delay-time=2;
 /file set ipstore.txt contents="0.0.0.0";
};
:global previousIP value=[/file get [find where name=ipstore.txt ] value-name=contents];
:if ($previousIP != $actualIP) do={
 :log info message=("Try to Update DuckDNS with actual IP ".$actualIP." -  Previous IP are ".$previousIP);
 /tool fetch mode=https keep-result=yes dst-path=duckdns-result.txt address=[:resolve www.duckdns.org] port=443 host=www.duckdns.org src-path=("/update?domains=ww.matrix.it&token=65843E27-A491-429F-84A0-30A947E20F92&ip=".$actualIP);
 /delay delay-time=5;
 :global lastChange value=[/file get [find where name=duckdns-result.txt ] value-name=contents];
 :global previousIP value=$actualIP;
 /file set ipstore.txt contents=$actualIP;
 :if ($lastChange = "OK") do={:log warning message=("DuckDNS update successfull with IP ".$actualIP);};
 :if ($lastChange = "KO") do={:log error message=("Fail to update DuckDNS with new IP ".$actualIP);};
};



Remember to add Karma if you find this info useful...
Thanks.
.

Hi - when I try to use this, it appears that there is another private address between the my Mikrotik router and the internet. So it returns a private address. Any other way I can do this?
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 895
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Jul 29, 2019 5:14 pm

Hi - when I try to use this, it appears that there is another private address between the my Mikrotik router and the internet. So it returns a private address. Any other way I can do this?
You could get your Ip this way:
/tool fetch mode=http http-method=get url=http://icanhazip.com/ dst-path=myip.txt
But honestly, does it make sense to register duckdns when your router is behind a NAT?
-Chris
Christopher Diedrich
MTCNA, MTCUME, MTCWE
Basel, Switzerland
Bremen, Germany

There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data
 
badwithnetworking
just joined
Posts: 8
Joined: Mon Jul 29, 2019 9:20 am

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Jul 29, 2019 5:46 pm

Hi - when I try to use this, it appears that there is another private address between the my Mikrotik router and the internet. So it returns a private address. Any other way I can do this?
You could get your Ip this way:
/tool fetch mode=http http-method=get url=http://icanhazip.com/ dst-path=myip.txt
But honestly, does it make sense to register duckdns when your router is behind a NAT?
-Chris

You are right. Maybe its not a private address. Basically my Fibre modem goes into ether1. When I set it using that script, the ip address is different than what I see if I use something like https://whatismyipaddress.com/.

Script gives me 172.22.###.###
Whatismyipaddress gives me a 103.252.###.### number

What could be going on here?
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 895
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: DuckDNS Update Script (free DynDNS alternative)

Mon Jul 29, 2019 5:49 pm

It pretty much looks like a private address - 172.22/16 is within 172.16/12 which is a private range.
And since the initial script is pulling the address from the interface, I'm sure you have a private address and your ISP is NATing your address.
-Chris
Christopher Diedrich
MTCNA, MTCUME, MTCWE
Basel, Switzerland
Bremen, Germany

There are 10 types of people: Those who understand binary and those who don't.
There are two types of people: Those who can extrapolate from incomplete data
 
badwithnetworking
just joined
Posts: 8
Joined: Mon Jul 29, 2019 9:20 am

Re: DuckDNS Update Script (free DynDNS alternative)

Sun Aug 04, 2019 6:09 pm

Ok no problem. I will just pay a premium for a static IP. Guess there is no way around it.

Thanks

Who is online

Users browsing this forum: No registered users and 14 guests