Code: Select all
:local IPv6 "true"
:local APIurl "https://USER:TOKEN@ipv4.tunnelbroker.net/nic/update?hostname=TUNNEL-ID&myip="
:global WANInterface "PPPOE"
:local previousIP ""
:local WANip ""
:local ipN ""
:local APIn
:local APIu
:set $APIn "true"
:set $APIu "true"
:if ($IPv6 = "true") do={
:local currentIP ([/interface pppoe-client monitor [find name=$WANInterface] once as-value]->"local-address")
:set WANip $currentIP
:set ipN $currentIP
}
:if ([/file find name=disk/db/tb.tmp.txt] = "") do={
:log error "No previous ip address file found, createing..."
:set previousIP $WANip
:execute script=":put $WANip" file="/disk/db/tb.tmp"
#:error message="No previous ip address file found."
:log warning ("TB API: Updating, please wait! Setting = $WANip")
:do {/tool fetch output=none url="$APIurl$WANip"} on-error={
:log error "IPv6: API is down!"
:set $APIn "false"
}
:if ($APIn=true) do={
:log warning ("TB API: $WANip IP address seted.")
}
:set $APIn true
} else={
:if ( [/file get [/file find name=disk/db/tb.tmp.txt] size] > 0 ) do={
:global content [/file get [/file find name="disk/db/tb.tmp.txt"] contents]
:global contentLen [ :len $content ] ;
:global lineEnd 0
:global line "";
:global lastEnd 0
:set lineEnd [:find $content "\n" $lastEnd ]
:set line [:pick $content $lastEnd $lineEnd]
:set lastEnd ( $lineEnd + 1 )
:if ( [:pick $line 0 1] != "#" ) do={
#:local previousIP [:pick $line 0 $lineEnd ]
:set previousIP [:pick $line 0 $lineEnd ];
:set previousIP [:pick $previousIP 0 [:find $previousIP "\r"]]
}
}
}
:if ($previousIP != $WANip) do={
:do {/tool fetch output=none url="$APIurl$WANip"} on-error={
:log error "IPv6: API is down!"
:set $APIu false
}
:if ($APIu=true) do={
:log warning ("TB API: $WANip IP address updated.")
/ip dns cache flush
:if ( [/file get [/file find name=disk/db/tb.tmp.txt] size] > 0 ) do={
/file remove disk/db/tb.tmp.txt
:execute script=":put $WANip" file="/disk/db/tb.tmp"
}
:set $APIu true
}
}