I use a script to grab the wan ip address from a pppoe interface. This script worked find in 3.30 but when I run it in 4.2 I get an error. Can anyone see what is wrong with this script?
:global wanip
:global waninterface
:global lastwanip
:local int
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
:if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
:global waninterface [/ip route get $int interface]
}
}
:set wanip [:pick [/ip address get [/ip address find interface=$waninterface] address] 0 [:find [/ip address get [/ip address find interface=$waninterface] address] "/"]]
:if ([ :typeof $wanip ] = nil ) do={
:log info ("WAN: No ip address present on " . $waninterface . ", please check.")
} else={
:if ($wanip != $lastwanip) do={
:log warning ("WAN ip address changed! " . $waninterface . " changed to: " . $wanip)
:global lastwanip $wanip
/interface 6to4 set sixbone local-address=$wanip
/system script run freedns ;
:log warning ("Update Done! ")
}
:global lastwanip $wanip ;
}
I don’t know if that’s a bug or intended. It’s possible that this value is only exposed in the routing-test package. Were you using routing-test on 3.30, but aren’t using it on 4.2? If so try installing that and test again.
A simple workaround for you for now on your system as is should be to hard code the interface name instead of dynamically finding the first quad-zero route that doesn’t have routing-marks on it:
:global wanip
:global lastwanip
:set wanip [:pick [/ip address get [/ip address find interface="YOUR_INTERFACE_NAME_HERE"] address] 0 [:find [/ip address get [/ip address find interface=YOUR_INTERFACE_NAME_HERE"] address] "/"]]
:if ([ :typeof $wanip ] = nil ) do={
:log info ("WAN: No ip address present on YOUR_INTERFACE_NAME_HERE, please check.")
} else={
:if ($wanip != $lastwanip) do={
:log warning ("WAN ip address changed! YOUR_INTERFACE_NAME_HERE changed to: " . $wanip)
:global lastwanip $wanip
/interface 6to4 set sixbone local-address=$wanip
/system script run freedns ;
:log warning ("Update Done! ")
}
:global lastwanip $wanip ;
}
But I don’t know if any other scripts you use need the waninterface global.