I’ve spent a couple of hours searching for the right way to grab the IP address of my Microtik switch directly from a script (in Mikrotik scripting language) without success.
The big problem is that the system Ip address of a switch is bound to a specific interface and it could be any ethernet port (from ether1 to etherN) or also the bridge.
Here it is! This is a small script to find (and save in a local variable) the IP address of the switch finding it through every available interface. I find it very useful to print the IP address of the switch in the email.
:local ip
:local iAdd [:toarray [/ip address find where interface~"ether" || interface~"bridge"]]
:foreach i in=$iAdd do={
:set ip[/ip address get $i address]
:set ip[:pick $ip 0 ([:len $ip]-3) ];
:log info "Current IP for interface $i is $ip"
}