##############Script Settings################## :local EXTif "ext" :local TUNif "6to4tun" :local LOCif "local" ############################################### :local EXTipv4 [/ip address get [find interface=$EXTif] address]; :local TUNipv4 [/interface 6to4 get [find name=$TUNif] local-address]; :for i from=( [:len $EXTipv4] - 1) to=0 do={ :if ( [:pick $EXTipv4 $i] = "/") do={ :set $EXTipv4 ([:pick $EXTipv4 0 $i]); } } :global dec2hex do={ :local hex "" :local dec [:tonum $1] :for i from=0 to=4 step=4 do={ :set hex ([:pick "0123456789ABCDEF" (($dec>>$i)&0xf) ((($dec>>$i)&0xf)+1)].$hex) } :return ([:tostr $hex]) } :local 6to4prefix do={ :global dec2hex :local oct :local ipv6 "2002:" :local tmp 0 :local c 0 :local ipv4 $1 :for i from=0 to=( [:len $ipv4] - 1) do={ :if ( [:pick $ipv4 $i] = "." || [:pick $ipv4 $i] = "/") do={ :set oct ([:pick $ipv4 $tmp $i]) :set tmp ($i+1) :set ipv6 ("$ipv6".[$dec2hex $oct]) :if ( c =1 || c =3) do={ :set ipv6 ("$ipv6".":") } :set c (c+1) } } :return ($ipv6) } :if ( $TUNipv4 != $EXTipv4 ) do={ /interface 6to4 set [find name=$TUNif] local-address=$EXTipv4 /ipv6 address remove [find interface=$TUNif] /ipv6 address remove [find interface=$LOCif] :local ipv6new [$6to4prefix ($EXTipv4."/")] :log info ($ipv6new) /ipv6 address add interface=$TUNif advertise=no address=("$ipv6new".":1/48") /ipv6 address add interface=$LOCif advertise=yes address=("$ipv6new".":1/64") }
Source: https://habr.com/ru/post/326076/
All Articles