I made a script that attempt to extract the MAC address from the first interface on the router:
:put [/interface ethernet get 0 mac-address]
It was all working fine until today when I updated one of my routers’ OS version from “5.18” to “6.19”.
The returned MAC address changed from being the first interface to the second.
I am guessing the interfaces changed IDs because their names when sorted alphabetically isn’t in the same order as the default names.
Before update:
Flags: X - disabled, R - running, S - slave
# NAME MTU MAC-ADDRESS ARP MASTER-PORT SWITCH
0 R Wan 1500 xx:xx:xx:xx:xx:FA enabled
1 R Lan1 1500 xx:xx:xx:xx:xx:FB enabled none switch1
2 S Lan2 1500 xx:xx:xx:xx:xx:FC enabled Lan1 switch1
3 S Lan3 1500 xx:xx:xx:xx:xx:FD enabled Lan1 switch1
4 S Lan4 1500 xx:xx:xx:xx:xx:FE enabled Lan1 switch1
After update:
Flags: X - disabled, R - running, S - slave
# NAME MTU MAC-ADDRESS ARP MASTER-PORT SWITCH
0 R Lan1 1500 xx:xx:xx:xx:xx:FB enabled none switch1
1 S Lan2 1500 xx:xx:xx:xx:xx:FC enabled Lan1 switch1
2 S Lan3 1500 xx:xx:xx:xx:xx:FD enabled Lan1 switch1
3 S Lan4 1500 xx:xx:xx:xx:xx:FE enabled Lan1 switch1
4 R Wan 1500 xx:xx:xx:xx:xx:FA enabled
I found this to work better for version “6.19”:
:put [/interface get [/interface find default-name=ether1] mac-address]
Problem is that the “default-name” property isn’t available in OS version “5.18”.
So is there a way to always get the first interface, no matter the OS version?
Or maybe a way to check which way would work?
I want to be able to use the same script on all my routers no matter the OS version they are running.
I am mostly trying to avoid using the interface’s name if possible, because it could change depending on the router.
Also if someone maybe know at what OS version this was changed, I’d very much like to know too.