From e1f134ead584c7b2e9ed406f5520d7f1a23294aa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 5 Jul 2018 15:29:26 +0200 Subject: add scripts --- update-tunnelbroker | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 update-tunnelbroker (limited to 'update-tunnelbroker') diff --git a/update-tunnelbroker b/update-tunnelbroker new file mode 100644 index 0000000..cce2c0c --- /dev/null +++ b/update-tunnelbroker @@ -0,0 +1,30 @@ +# RouterOS script: update-tunnelbroker +# Copyright (c) 2013-2018 Christian Hesse + +:local tunnelurl "ipv4.tunnelbroker.net"; +:local tunneluser "user"; +:local tunnelpass "v3ry-s3cr3t"; +:local tunnelid "user-XXX.tunnel.tserv6.fra1.ipv6.he.net"; + +# name of the local tunnel interface +:local tunnelint "tunnelbroker"; + +# 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 on interface with default route +:local tunnelip [ / ip route get [ / ip route find where gateway=[ / ip route get [ / ip route find where dynamic=yes and dst-address="0.0.0.0/0" dynamic active=yes ] gateway ] dst-address!="0.0.0.0/0" ] pref-src ]; + +# Did we get an IP address to compare? +:if ([ :typeof $tunnelip ] = nil) do={ + :log warning ("No default route? Could not get address, please check."); +} else={ + :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."; + } +} -- cgit v1.2.3-54-g00ecf