Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting router MAC address #60

Open
mahmoud63 opened this issue Feb 15, 2020 · 3 comments
Open

Getting router MAC address #60

mahmoud63 opened this issue Feb 15, 2020 · 3 comments

Comments

@mahmoud63
Copy link

Is there is any way to get mikrotik router MAC address

@boenrobot
Copy link
Member

Sure.

$macAddress = $util->setMenu('/interface')->get('ether1', 'mac-address');

Just replace "ether1" with the name of the interface you want to get the MAC address of.

@mahmoud63
Copy link
Author

mahmoud63 commented Feb 17, 2020

thanks for reply,
But the situation I have now that I have Mikrotik router connected to my captive portal and I want to get router mac address and send it to server
I tried this code

$client =new RouterOS\Client('192.168.88.1', 'admin', 'password');

`$snmpRequest = new RouterOS\Request(':put [/interface ethernet get [/interface ethernet find default-name=ether1] mac-address ]');`

$snmpResponses = $client->sendSync($snmpRequest);

`$nasID = RouterOS\Script::escapeString($snmpResponses->getProperty('value'), true);`

but while testing the captive portal stuck at this link --> http://192.168.88.1
note that I changed the password to current password

@boenrobot
Copy link
Member

boenrobot commented Feb 17, 2020

You can't use nested commands in Request(). You must call each command individually. Also, "put" is kind of useless in the API, though it does work... It's just that it can only output a string that it was explicitly given. Also, why are you calling RouterOS\Script::escapeString() on the returned value?

What probably happened in your code is there was an error reply, but you took its "value" property anyway.

You can emulate more closely the nested command syntax with Util, but the point remains even there:

$util = new RouterOS\Util($client);
$util->setMenu('/interface ethernet');
$nasID = $util->get(
    $util->find(RouterOS\Query::where('default-name', 'ether1')),
    'mac-address'
);

The above would give you the mac-address into the variable $nasID via two API calls - one to get the internal ID of the interface with default name "ether1", and the second one to get its mac-address. And it would throw an exception if there's an error reply anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants