Community discussions

MikroTik App
 
User avatar
trex2000
newbie
Topic Author
Posts: 29
Joined: Thu Aug 17, 2023 9:40 am

DDNS (Freedns) upgrade script not working as expected.

Thu Aug 17, 2023 10:13 am

Hello,
I've tried to setup and automated DDNS update script when the PPPOE connection is up. I've read all the forums, and the old scripts (that mostly use tool fetch do not work any more due to permission issues.
Basically, to update the IP address at freedns, one must fetch the following URL:
https://freedns.afraid.org/dynamic/update.php?HASH_VALUE==
In the old versions one would simply put in the PPOE profile, in the "on Up" section the fetch command and that's all.
But these seems to not work any more due to permission rights issues.
So now I did the following.
I created the following script and named it "freedns_update":
:log info ("Freedns IP address update started");
:delay 10;
:resolve freedns.afraid.org
:delay 10;
/tool fetch url="https://freedns.afraid.org/dynamic/update.php?HASH_VALUE==" keep-result=no
:log info ("Freedns IP address updated");
The closest I got is the following:
In the System -> Scripts section, for this script I've ticked all permissions (including 'test' and 'Don't require permissions')

In the PPOE scripts section, at "on Up" I've set to run it:
/system script run "freedns_update"
When the link comes up, it indeed runs the script, but never finishes.
It displays only:
"Freedns IP address update started"
but never gets to the line which logs:
"Freedns IP address updated"
I've also set up a Scheduler, to run this script every day, under System-> Scheduler:
/system script run freedns_update
This runs ok, every day I see in the log both entries from above and also the IP address is kept in sync.
Here I also see that the owner is "admin" and also under policy, I've ticked everything.

Below are the screenshots:
freedns.png
What could be the problem ?
You do not have the required permissions to view the files attached to this post.
 
sbotnick
just joined
Posts: 22
Joined: Fri Apr 21, 2017 10:54 pm

Re: DDNS (Freedns) upgrade script not working as expected.

Sat Aug 19, 2023 2:36 am

For diagnostic I would change keep-result=no to keep-result=yes to see what the response is from the server when the script is run manually.

That said, I am kind of curious as to where your hash value that identifies you to the server is.

FWIW, on their front page they show a different update URL, so that might be your solution right there:

https://freedns.afraid.org/
 
User avatar
trex2000
newbie
Topic Author
Posts: 29
Joined: Thu Aug 17, 2023 9:40 am

Re: DDNS (Freedns) upgrade script not working as expected.

Sat Aug 19, 2023 3:59 pm

The URL is fine, as when I run the script via scheduler, it works. Also running it manually it works. The only case when it doesn't is when it's triggered on "on up" by the pppoe profile. Also in this case, the first log entry is written, only that it looks like it never finishes, at least the last log entry does not appear and it does not update the IP.
 
User avatar
trex2000
newbie
Topic Author
Posts: 29
Joined: Thu Aug 17, 2023 9:40 am

Re: DDNS (Freedns) upgrade script not working as expected.

Sat Aug 19, 2023 4:00 pm

Freedns has 2 versions , an old one and v2, which is shorter and looks different. It doesn't really matter which one do you use.
 
User avatar
trex2000
newbie
Topic Author
Posts: 29
Joined: Thu Aug 17, 2023 9:40 am

Re: DDNS (Freedns) upgrade script not working as expected.  [SOLVED]

Sat Aug 19, 2023 5:26 pm

:global WANInter "pppoe-out1"
:global AfraidDomain "mydomain.freedns.org"
:local InternetCheckTimeoutCount 10
#Do not modify below
:log info ("*** Freedns IP address update started ****");
#wait a minute to allow the PPOE connection to be established
:local stayInLoop true;
:local counter 0;
:while ($stayInLoop) do={
   :set counter ($counter + 1);
   #check if internet is up
   :if ([:typeof ([:ping address=8.8.8.8 count=1 as-value]->"time")] = "nothing") do={
		:log info "Freedns: reply NOT received, retry no $counter in 10 seconds"
		:delay 10
	} else={
		:log info "Freedns: Internet is up"
		:set stayInLoop false;
		:global IPCurrent [/ip address get [find interface=$WANInter] address];
		# FOR loop strips CIDR from end of IP address
		:for i from=( [:len $IPCurrent] - 1) to=0 do={
		  :if ( [:pick $IPCurrent $i] = "/") do={ 
			:global NewIP [:pick $IPCurrent 0 $i];
			:global NoCIDR [:pick $IPCurrent 0 $i];
			:log info "Current IP: $NoCIDR"
			:global AfraidIP [:resolve $AfraidDomain];
			:log info "Afraid IP address: $AfraidIP"
			#check if if associated to domain is the same as the current ip
			:if ($AfraidIP != $NewIP) do={
			  #the IPs are different, update IP at Afraid.org
			  :log info "IPs are different, update IP at Afraid.org"
			  /tool fetch url="https://freedns.afraid.org/dynamic/update.php?HASH_VALUE==" keep-result=no
			  :log info "Afraid.org New IP Found and updated : $AfraidDomain - $NewIP"
			 } else={
			 :log info "Afraid.org, No need to update IP, as: CURRENT IP: $NoCIDR  Afraid.org IP: $AfraidIP";
			}
		   } 
		}		
	}
   #if the timeout timer expires and there is no internet, then abord
   :if ($counter=$InternetCheckTimeoutCount) do={:set stayInLoop false;}
}
:log info "**** Freedns update script finished **** "

 
loboAT
just joined
Posts: 7
Joined: Sat Oct 21, 2023 3:52 pm

Re: DDNS (Freedns) upgrade script not working as expected.

Fri Oct 27, 2023 2:05 pm

I modified the script so that it also works if you are a modem and receive a private IP on WAN Interface:

:global AfraidDomain "xxxx.mooo.com"
:global AfraidUpdateURL "https://freedns.afraid.org/dynamic/update.php?xxxx"
:local InternetCheckTimeoutCount 10
#Do not modify below
:log info ("*** Freedns IP address update started ****");
:local stayInLoop true;
:local counter 0;
:while ($stayInLoop) do={
   :set counter ($counter + 1);
   #check if internet is up
   :if ([:typeof ([:ping address=8.8.8.8 count=1 as-value]->"time")] = "nothing") do={
    :log info "Freedns: reply NOT received, retry no $counter in 10 seconds"
    :delay 10
  } else={
    :log info "Freedns: Internet is up"
    :set stayInLoop false;
    :global IPCurrent [:put [/ip cloud get public-address]];;
    :log info "Current IP: $IPCurrent"
    :global AfraidIP [:put [:resolve $AfraidDomain server=1.1.1.1]];
    :log info "Afraid IP address: $AfraidIP"
    #check if if associated to domain is the same as the current ip
    :if ($AfraidIP != $IPCurrent) do={
      #the IPs are different, update IP at Afraid.org
      :log info "IPs are different, update IP at Afraid.org"
      /tool fetch url=$AfraidUpdateURL keep-result=no
      :log info "Afraid.org New IP Found and updated : $AfraidDomain - $IPCurrent"
     } else={
     :log info "Afraid.org, No need to update IP, as: CURRENT IP: $NoCIDR  Afraid.org IP: $AfraidIP";
    }
  }
   #if the timeout timer expires and there is no internet, then abort
   :if ($counter=$InternetCheckTimeoutCount) do={:set stayInLoop false;}
}
:log info "**** Freedns update script finished **** "

Who is online

Users browsing this forum: No registered users and 4 guests