aboutsummaryrefslogtreecommitdiffstats
path: root/update-tunnelbroker
blob: ee8e0e8abe6319a65b88b51695c3a8cae12f29e3 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!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.";
}