routeros-scripts/update-tunnelbroker
Michael Gisbers ca16f286ef update-tunnelbroker: move configuration to global-config...
... and get the external ip address from cloud.

Signed-off-by: Michael Gisbers <michael@gisbers.de>
Signed-off-by: Christian Hesse <mail@eworm.de>
2019-01-02 15:02:42 +01:00

34 lines
1.1 KiB
Plaintext

#!rsc
# RouterOS script: update-tunnelbroker
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
# Michael Gisbers <michael@gisbers.de>
:global tunnelurl;
:global tunneluser;
:global tunnelpass;
:global tunnelid;
:global tunnelint;
:if ([ / ip cloud get ddns-enabled ] != true) do={
:error "IP cloud DDNS is not enabled.";
}
# get the last ip address from tunnel interface
:local tunnellastip [ / interface 6to4 get [ / interface 6to4 find where name=$tunnelint ] local-address ];
# Get the current ip address from cloud
/ ip cloud force-update;
while ([ / ip cloud get status ] != "updated" ) do={
:delay 1s;
}
:local tunnelip [ / ip cloud get public-address ];
:if ($tunnelip != $tunnellastip) do={
:log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $tunnelip);
/ tool fetch mode=https address=$tunnelurl user=$tunneluser password=$tunnelpass \
src-path=("/nic/update\?hostname=" . $tunnelid) keep-result=no;
/ interface 6to4 set [ / interface 6to4 find where name=$tunnelint ] local-address=$tunnelip;
} else={
:log debug "All tunnelbroker configuration is up to date.";
}