Community discussions

MikroTik App
 
RobVision
just joined
Topic Author
Posts: 1
Joined: Fri May 05, 2023 6:18 pm

DynDNS.com Update

Fri May 05, 2023 6:43 pm

Hello,

I would like to share the script to update dyndns.com IP.
I Started from existing script to assembly the one I need, I use it having 2x ISP (main and backup, not aggregated) to update DNS in case of failover of the primary connection and vice-versa.

# print some debug info
:log info ("<<<< RUNNING SCRIPT DYNDNS.COM UPDATE >>>>")

:local ddnsuser <yourUsername>
:local ddnspass <yourPassword>
:local ddnshost <yourDynDnsHost>

:local ipddns [:resolve $ddnshost];
:log info ("DynDNS script: Registered = $ipddns")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.com" src-path="/" dst-path="/dyndns.checkip.html"
:delay 1
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local ipfresh [:pick $result $startLoc $endLoc]
:log info "DynDNS script: Internet IP = $ipfresh"

 
:if ($ipddns != $ipfresh) do={
   :log info "DynDNS: Update IP needed, Sending UPDATE...!"
   :local str "/nic/update?hostname=$ddnshost&myip=$ipfresh&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
   /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser \
         password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
    :delay 1
    :local str [/file find name="DynDNS.$ddnshost"];
    /file remove $str
    :global ipddns $ipfresh
  :log info "DynDNS script: IP updated to $ipfresh!"
    } else={
     :log info "DynDNS script: No changes";
    }
}

 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DynDNS.com Update

Sat May 06, 2023 3:42 pm

This script use uselessly the NAND/Flash and concur to premature memory failure,

and at the same time:

TAG: ###RCHCK###
 
mdar
just joined
Posts: 1
Joined: Mon Jan 08, 2024 5:49 pm

Re: DynDNS.com Update

Mon Jan 08, 2024 6:02 pm

This script use uselessly the NAND/Flash and concur to premature memory failure,

and at the same time:

TAG: ###RCHCK###
Hello, I am trying to learn scripting in Mikrotik and I am very interested in your contribution. Could you please tell me why the script you mention can cause failures in the router's memory, or tell me where I can read about the topic.
Thank you so much
 
ther33
just joined
Posts: 15
Joined: Sun Apr 02, 2023 11:58 pm

Re: DynDNS.com Update

Tue Jan 09, 2024 3:37 am

It writes to NAND/Flash for no reason when it could just output to a variable using the output=user parameter of /tool/fetch. Flash has a limited number of write cycles. Writing to NAND/Flash on embedded devices is something to be avoided if possible. For example: excessive logging on older Tesla Model S caused premature NAND to failure, breaking vehicle functionality.

Please don't revive dead threads to ask questions unnecessarily. Rextended's warning was good enough so that anyone who doesn't really understand the issue should know to avoid using the script. Anyone who knows how to read the script and understands the issue would come to the same conclusion as him.

Correction: original post had output=file, corrected to output=user
Last edited by ther33 on Tue Jan 09, 2024 8:44 am, edited 1 time in total.
 
na6cet
just joined
Posts: 2
Joined: Mon Aug 21, 2023 11:42 am

Re: DynDNS.com Update

Tue Jan 09, 2024 7:59 am

It writes to NAND/Flash for no reason
Then I assume the script described on dynu's website has the same problem?

https://www.dynu.com/DynamicDNS/IPUpdat ... ynamic-DNS

Would be good to know because I'm using it!
output to a variable using the output=file parameter of /tool/fetch
I assume you mean output=user because output=file is the default?
Last edited by na6cet on Tue Jan 09, 2024 8:10 am, edited 1 time in total.
 
ther33
just joined
Posts: 15
Joined: Sun Apr 02, 2023 11:58 pm

Re: DynDNS.com Update

Tue Jan 09, 2024 9:00 am

Yeah, I think rextended was being a bit dramatic. It is probably a write of less than 1 KiB in size and would typically repeat every 5 minutes. Assuming it a 1 KiB write every 5 minutes, It would take 56.8889 days to write 16 MiB. So if wear leveling on the flash works the way I know it does for a proper TLC SSD then it should take 56.8889*2000=13,777.8 days or ~311 years to write 2,000 cycles and wear the flash out.

I have no idea how wear leveling works for the kinds of flash used in MikroTik products or what their write endurance is. Also, this is not the only thing writing to the flash and writes from all sorts of sources can add up.

As I said, it is definitely bad practice to use flash if it is avoidable. Here it definitely is. The script you linked can just be modified to just output to a variable directly and the file deletion part can be removed.

Corrected: total years calculation was inaccurate.
Correction (by rextended): Block size >=4KiB: each write would be 4KiB, therefore a more accurate (but still optimistic) estimate is 14.2222 days for a full cycle or ~80 years for 2000 cycles.
Last edited by ther33 on Tue Jan 09, 2024 7:00 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: DynDNS.com Update

Tue Jan 09, 2024 10:34 am

It is probably a write of less than 1 KiB in size and would typically repeat every 5 minutes. Assuming it a 1 KiB write every 5 minutes, It would take 56.8889 days to write 16 MiB.

I have no idea how wear leveling works for the kinds of flash used in MikroTik products or what their write endurance is.
On flash, if you write just one bit, an entire page of memory is rewritten.
I don't know the page and block size in the chip used, but it can be 4KiB or more just for one bit changed on the page.

html code

<html><head><title>Current IP Check</title></head><body>Current IP Address: XXX.XXX.XXX.XXX</body></html>
So, if each time just the IP is written, are ~ 108Bytes (106 + \n or \r\n i do not check exactly)
For each 108Bytes are writed 4KiB.
4KiB for every 5 minutes = ~14 days (approx) for write 16MiB
(16MiB = 4096 times 4KiB, so 4096 time 5 minutes, so 20480 minutes, so 341,333_ hours, so 14,222_ days...)

So ~14 days are not ~57 days...

And all this without taking into account that there are those who monitor every minute, making the situation 5 times worse...

Assuming that each time a different memory page is written, the previous one must still be erased, so in reality double what I wrote is written, because rewriting/erasing is still writing...


But beyond any reasoning on consumption,
anything done badly, stays done badly.
(When alternative methods exist)
 
ther33
just joined
Posts: 15
Joined: Sun Apr 02, 2023 11:58 pm

Re: DynDNS.com Update

Tue Jan 09, 2024 6:49 pm

It is probably a write of less than 1 KiB in size and would typically repeat every 5 minutes. Assuming it a 1 KiB write every 5 minutes, It would take 56.8889 days to write 16 MiB.

I have no idea how wear leveling works for the kinds of flash used in MikroTik products or what their write endurance is.
On flash, if you write just one bit, an entire page of memory is rewritten.
I don't know the page and block size in the chip used, but it can be 4KiB or more just for one bit changed on the page.

html code

<html><head><title>Current IP Check</title></head><body>Current IP Address: XXX.XXX.XXX.XXX</body></html>
So, if each time just the IP is written, are ~ 108Bytes (106 + \n or \r\n i do not check exactly)
For each 108Bytes are writed 4KiB.
4KiB for every 5 minutes = ~14 days (approx) for write 16MiB
(16MiB = 4096 times 4KiB, so 4096 time 5 minutes, so 20480 minutes, so 341,333_ hours, so 14,222_ days...)

So ~14 days are not ~57 days...

And all this without taking into account that there are those who monitor every minute, making the situation 5 times worse...

Assuming that each time a different memory page is written, the previous one must still be erased, so in reality double what I wrote is written, because rewriting/erasing is still writing...


But beyond any reasoning on consumption,
anything done badly, stays done badly.
(When alternative methods exist)
Absolutely right. I knew what you were going to say before I even read it. NAND writes are in blocks and erasure is separate from writing, so there is a lot of write amplification. This is why enterprise SSDs specify the kind of writes and how full the drive is when describing endurance. Like Micron specifies 4K random with the drive 100% full for their 7450 SSDs.

Who is online

Users browsing this forum: Bing [Bot] and 32 guests