In the DHCP up script I get the interface and address + create a global variable:
:local WANif [/interface get $“interface” name]
:local WANip [:tostr $“lease-address”]
[:parse “:global $WANif $WANip”] ← THANKS to REXTENDED for this! :put $WAN1 → 100.10.20.40
In the DHCP down, I know the interface name but not the previous IP:
:local WANif [/interface get $“interface” name]
:log warning “Interface down, IP 100.10.20.40 is not available” ← to retrieve IP from interface name, $WANif → WAN1 or WAN2 , then with the WAN name i should “call” the global variable $WAN1 → 100.10.20.40, something like [$[$WANif]]
Simply create one global array with inside interface / ip pair “WANx=o.l.d.ip;WANy=an.othe.r.ip”,
is more easy and intuitive.
WRITE
:global globalvarname
:local WANif [/interface get $“interface” name]
:local WANip [:tostr $“lease-address”]
:set ($globalvarname->$WANif) $WANip
READ
:global globalvarname
:local WANif [/interface get $“interface” name]
:local previousIP ($globalvarname->$WANif)
EXTRA: Consider that one interface can have more than on IP, and get do not support arrays as results…
Thanks again @rextended, you’re so clever!
I wasn’t that good integrating what I was trying to achieve, in the end, using :if ($WANif=WAN1) do= else=, I got a variable of WAN1IP WAN1=100.10.20.40 which is fine, it’s just for hobby.