update-tunnelbroker: get public address from website

This is a good condidate:

https://showipv6.de/

We can drop the cloud code, which seems to be unreliable in somd
situations.
This commit is contained in:
Christian Hesse 2022-10-09 19:45:18 +02:00
parent c95cbdbc1e
commit e7995fa06b
2 changed files with 13 additions and 14 deletions

View file

@ -33,10 +33,6 @@ The configuration goes to interface's comment:
You should know you user name from login. The `id` is the tunnel's numeric You should know you user name from login. The `id` is the tunnel's numeric
id, `pass` is the *update key* found on the tunnel's advanced tab. id, `pass` is the *update key* found on the tunnel's advanced tab.
Also enabling dynamic DNS in Mikrotik cloud is required:
/ip/cloud/set ddns-enabled=yes;
See also See also
-------- --------

View file

@ -17,16 +17,22 @@
:global LogPrintExit2; :global LogPrintExit2;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:if ([ /ip/cloud/get ddns-enabled ] != true) do={ :if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false || \
$LogPrintExit2 error $0 ("IP cloud DDNS is not enabled.") true; [ $CertificateAvailable "R3" ] = false) do={
$LogPrintExit2 error $0 ("Downloading required certificate failed.") true;
} }
# Get the current ip address from cloud :local PublicAddress;
/ip/cloud/force-update; :do {
:while ([ /ip/cloud/get status ] != "updated") do={ :set PublicAddress ([ /tool/fetch check-certificate=yes-without-crl \
:delay 1s; "https://ipv4.showipv6.de/short" output=user as-value ]->"data");
} on-error={
$LogPrintExit2 error $0 ("Failed getting public address.") true;
}
:if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={
$LogPrintExit2 warning $0 ("The address " . $PublicAddress . " is not configured on your device. NAT by ISP?") false;
} }
:local PublicAddress [ /ip/cloud/get public-address ];
:foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={ :foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={
:local InterfaceVal [ /interface/6to4/get $Interface ]; :local InterfaceVal [ /interface/6to4/get $Interface ];
@ -36,9 +42,6 @@
:local Success false; :local Success false;
:local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ]; :local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ];
:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 error $0 ("Downloading required certificate failed.") true;
}
$LogPrintExit2 info $0 ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress) false; $LogPrintExit2 info $0 ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress) false;
:while ($I < 3 && $Success = false) do={ :while ($I < 3 && $Success = false) do={
:do { :do {