routeros-scripts/bridge-port-to-default

30 lines
1.1 KiB
Text

#!rsc
# RouterOS script: bridge-port-to-default
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
#
# reset bridge ports to default bridge
:global BridgePortTo;
:local Len ([ :len $BridgePortTo ] + 1);
:if ($Len = 1) do={
:delay 1s;
:set Len ([ :len $BridgePortTo ] + 1);
}
:foreach BridgePort in=[ / interface bridge port find where comment!="" ] do={
:local BridgePortVal [ / interface bridge port get $BridgePort ];
:foreach Comment in=[ :toarray ($BridgePortVal->"comment") ] do={
:if ([ :pick $Comment 0 $Len ] = ($BridgePortTo . ":")) do={
:local BridgeDefault [ :pick $Comment $Len [ :len $Comment ] ];
:if ($BridgeDefault != $BridgePortVal->"bridge") do={
:log info ("Changing interface " . $BridgePortVal->"interface" . " to " . $BridgePortTo . " bridge " . $BridgeDefault);
/ interface bridge port set bridge=$BridgeDefault $BridgePort;
/ ip dhcp-client renew [ find where interface=$BridgeDefault ];
} else={
:log debug ("Interface " . $BridgePortVal->"interface" . " already connected to " . $BridgePortTo . " bridge " . $BridgeDefault);
}
}
}
}