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..