http://wiki.mikrotik.com/wiki/Hurricane ... nt_updater
I made some changes based on original author script:
* Check if WAN interface IP and "6to4 Tunnel" Local Address are the same, if they are equal script don't update the tunnel info.
* Script only change the "6to4 Tunnel" Local Address if a valid string is returned from server.
* Now you can configure a scheduler with this script and don't flood the update server.
Script name (ie: update_ipv6_tunnel)
Code: Select all
# Update Hurricane Electric IPv6 Tunnel Client IPv4 address
:local HEtunnelinterface "<this router's tunnel interface name>"
:local HEtunnelid "<tunnel id>"
:local HEuserid "<user id>"
:local HEmd5pass "<md5 hash of password>"
:local HEupdatehost "ipv4.tunnelbroker.net"
:local HEupdatepath "/ipv4_end.php"
:local WANinterface "WAN"
: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)
}
:local HEtunnelipv4addr
# Get current TUNNEL interface IP address
:set HEtunnelipv4addr [/interface 6to4 get $HEtunnelinterface local-address]
:if ([:len $HEtunnelipv4addr] = 0) do={
:log error ("Could not get IP for interface " . $HEtunnelinterface)
:error ("Could not get IP for interface " . $HEtunnelinterface)
}
:if ($HEipv4addr != $HEtunnelipv4addr) do={
:local htmlcontent
:log info ("Updating IPv6 Tunnel " . $HEtunnelid . " Client IPv4 address to new IP " . $HEipv4addr . "...")
/tool fetch mode=http \
host=($HEupdatehost) \
url=("http://" . $HEupdatehost . $HEupdatepath . \
"?ipv4b=" . $HEipv4addr . \
"&pass=" . $HEmd5pass . \
"&user_id=" . $HEuserid . \
"&tunnel_id=" . $HEtunnelid) \
dst-path=($outputfile)
:set htmlcontent [/file get $outputfile contents]
/file remove $outputfile
:if ($htmlcontent = "+OK: Tunnel endpoint updated to: $HEipv4addr" || \
$htmlcontent = "-ERROR: This tunnel is already associated with this IP address. Please try and limit your updates to IP changes.") do={
:log info "OK Tunnel endpoint updated to $HEipv4addr. Updating 6to4 interface"
/interface 6to4 {
:if ([get ($HEtunnelinterface) local-address] != $HEipv4addr) do={
:log info ("Updating " . $HEtunnelinterface . " local-address with new IP " . $HEipv4addr . "...")
set ($HEtunnelinterface) local-address=$HEipv4addr
}
}
} else={
:log info "Update FAIL"
:log info $htmlcontent
}
} else={
:log info ("This tunnel is already associated with current public IP address (" . $WANinterface . "). Address update is not necesary")
}
Code: Select all
/system scheduler
add disabled=no interval=30s name=Check_Tunnel_IP on-event=\
update_ipv6_tunnel start-time=startup