Page 1 of 1

Get Mac Address first interface

Posted: Tue Apr 11, 2017 1:05 pm
by jamecollins
Dear all,
I'm new with RouterOS script and I have some problem need help. How can I get mac-address the first interface on my router.
Image
Thanks for your support

Re: Get Mac Address first interface

Posted: Tue Apr 11, 2017 9:18 pm
by sid5632
:put [/interface ethernet get [/interface ethernet find default-name=ether1] mac-address ]

Re: Get Mac Address first interface

Posted: Wed Apr 12, 2017 4:16 am
by jamecollins
:put [/interface ethernet get [/interface ethernet find default-name=ether1] mac-address ]
Very nice. Thanks for your support

Re: Get Mac Address first interface

Posted: Fri Sep 14, 2018 9:31 pm
by DavidGB
Hi,

I need help with my code. I get mac adress from microtik wifi client to do some actions but I need to know mac adress from my ISP router. I have conected this router to ether1 and I´ve tried your code but doesn´t work. Can you help me?

My code is the following:

{
:local iPhone [/int wire reg find mac-address="38:71:DE:E4:F8:FB"];

:if ($iPhone!="") do={
/tool fetch url="http://<MyServerIP>/scada-remote" http-data="m=json&r=grp&fn=write&alias=33/1/45&value=1" http-method=post;
} else={
/tool fetch url="http://<MyServerIP>/scada-remote" http-data="m=json&r=grp&fn=write&alias=33/1/45&value=0" http-method=post;
}
}

I'm trying to add your code to search both routers but it does not work

Can anyone help me?

Thanks

Re: Get Mac Address first interface

Posted: Fri Sep 14, 2018 9:36 pm
by DavidGB
Hi,

I need help with my code...

I get the MAC from the Wifi devices of the Microtic but I need the ones from the ISP router. I'm trying with your code but it does not work for me. Somebody could help me?

This is my code:

{
:local iPhone [/int wire reg find mac-address="38:71:DE:E4:F8:FB"];

:if ($iPhone!="") do={
/tool fetch url="http://<IP>/scada-remote" http-data="m=json&r=grp&fn=write&alias=33/1/45&value=1" http-method=post;
} else={
/tool fetch url="http://remote:AAaa1111@192.168.1.205:4080/scada-remote" http-data="m=json&r=grp&fn=write&alias=33/1/45&value=0" http-method=post;
}
}

Re: Get Mac Address first interface

Posted: Thu Feb 18, 2021 1:41 pm
by rushlife
:put [/interface ethernet get [/interface ethernet find default-name=ether1] mac-address ]
thx a lot bro
awesome

Re: Get Mac Address first interface

Posted: Wed Nov 08, 2023 10:24 pm
by choks
:put [/interface ethernet get 0 mac-address ]  
works too , but much shorter to type.

or
:put [/interface ethernet get <current interface name> mac-address ]  

Re: Get Mac Address first interface

Posted: Thu Nov 09, 2023 1:59 am
by rextended
:put [/interface ethernet get 0 mac-address ]  
works too , but much shorter to type.
But it's also bullshit because numbers and ids shouldn't be used.
You could have saved yourself from necroposting with that shit.

The apparently correct one:
:put [/interface ethernet get [find where default-name=ether1] mac-address]

The apparently correct until someone not change the interface name
:put [/interface ethernet get ether1 mac-address]

The apparently correct shortest possible (until MikroTik do not add ambiguos values)
:put [/in et g [f default-name=ether1] ma]

The apparently correct short, but more readable (until MikroTik do not add ambiguos values)
:put [/int eth get [find default-name=ether1] mac]

But the only correct answer from the OP "Get Mac Address first interface" is:
:put [/int get ([find]->0) mac-address]
So literally is "put on the CLI what is obtained from Get the Mac Address from the first interface found"