Hurricane Electric IPv6 Tunnel - IPv4 Endpoint updater

From MikroTik Wiki
Revision as of 22:32, 5 March 2017 by Chupaka (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This script will update a Hurricane Electric IPv6 Tunnel Client IPv4 address.

This script uses the fetch command with the url= parameter. Check that your version of RouterOS -> /tool fetch supports this option.

This script also works great when integrated with a dynamic DNS updater script.

For complete instructions on how to update your Hurricane Electric IPv6 Tunnel Client IPv4 address, see this link: [1]

2017-03-05: Updated. Fresh version by mos6581 uses HTTPS and actual update URL

The script:

# Update Hurricane Electric IPv6 Tunnel Client IPv4 address

:local HEtunnelinterface "<<<6to4 Interface name>>>"
:local HEtunnelid "<<<Tunnel ID>>>"
:local HEuserid "<<<Username>>>"
:local HEmd5pass "<<<Update Key>>>"
:local HEupdatehost ""
:local HEupdatepath "/nic/update"
:local WANinterface "<<<WAN Interface name>>>"
:local outputfile ("HE-" . $HEtunnelid . ".txt")

# Internal processing below...
# ----------------------------------
:local HEipv4addr

# Get WAN interface IP address
:set HEipv4addr [/ip address get [/ip address find interface=$WANinterface] address]
:set HEipv4addr [:pick [:tostr $HEipv4addr] 0 [:find [:tostr $HEipv4addr] "/"]]

:if ([:len $HEipv4addr] = 0) do={
   :log error ("Could not get IP for interface " . $WANinterface)
   :error ("Could not get IP for interface " . $WANinterface)

# Update the HEtunnelinterface with WAN IP
/interface 6to4 {
   :if ([get ($HEtunnelinterface) local-address] != $HEipv4addr) do={
      :log info ("Updating " . $HEtunnelinterface . " local-address with new IP " . $HEipv4addr . "...")
      set ($HEtunnelinterface) local-address=$HEipv4addr

:log info ("Updating IPv6 Tunnel " . $HEtunnelid . " Client IPv4 address to new IP " . $HEipv4addr . "...")
/tool fetch mode=https \
                  host=($HEupdatehost) \
                  url=("https://" . $HEupdatehost . $HEupdatepath . \
                          "?hostname=" . $HEtunnelid . \
                          "&myip=" . $HEipv4addr) \
                  user=($HEuserid) \
                  password=($HEmd5pass) \
:log info ([/file get ($outputfile) contents])
/file remove ($outputfile)