# Hurricane Electric IPv6 Tunnel - IPv4 Endpoint updater - MikroTik Script RouterOS

    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] (http://ipv4.tunnelbroker.net/ipv4_end.php)

    2017-03-05: Updated. Fresh version by mos6581 (https://forum.mikrotik.by/viewtopic.php?t=249) uses HTTPS and actual update URL

    The script:

    # Update Hurricane Electric IPv6 Tunnel Client IPv4 address
    :local HEtunnelinterface "<<<6to4 Interface name>>>"
    :local HEtunnelid "<<>>"
    :local HEuserid "<<>>"
    :local HEmd5pass "<<>>"
    :local HEupdatehost "ipv4.tunnelbroker.net"
    :local HEupdatepath "/nic/update"
    :local WANinterface "<<>>"
    :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) \
                      dst-path=($outputfile)

    :log info ([/file get ($outputfile) contents])
    /file remove ($outputfile)
    Credit: wiki.mikrotik.com