In the following code snippet, it does not work when the MAC address does not exist in the Bridge Host table or ARP table to extract the corresponding interface.
Where is the error?
{
:local bridHost [/interface/bridge/host/print as-value]
:local arpTable [/ip/arp/print as-value]
:local iFace " "
# The following MACs are for testing purposes:
# :local macAddress "54:B7:BD:70:0F:B8" ; # This MAC does not exist in the bridge host table
:local macAddress "E0:CC:F8:E7:90:4A" ; # Yes, it does exist
:foreach id in=$bridHost do={
:if (($macAddress = ($id->"mac-address")) and ([:len ($id->"on-interface")] > 0)) do={
:set iFace ($id->"on-interface")
} else={
:foreach id2 in=$arpTable do={
:if (($macAddress = ($id2->"mac-address")) and ([:len ($id2->"interface")] > 0)) do={
:set iFace ($id2->"interface")
} else={
:set iFace "*no interface*"
}
}
}
}
:put $iFace
}