Get MAC address

Using ssh (putty.exe), I type the command

snmpget 10.9.8.7 -v1 -c public 1.3.6.1.2.1.2.2.1.6.1

And the result is

iso.3.6.1.2.1.2.2.1.6.1 = Hex-STRING: 58 10 8C 0D 8B 00

However, when I type the command

/tool snmp-get address=10.9.8.7 community=public version=1 oid=1.3.6.1.2.1.2.2.1.6.1

on the winbox terminal, the result is

1.3.6.1.2.1.2.2.1.6.1    octet-string     X\10\8C\r\8B\00

How to display the MAC correctly using the winbox terminal?

The value is technically correct… It’s just that It’s shown as an ASCII string. “58” is the hex value of “X”, and “0D” is the hex value for carriage return.

If you’re trying to automate, you should use the API instead of SSH.

f.e. using the PHP client from my signature:

<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';

$client = new RouterOS\Client('192.168.88.1', 'admin', 'password');
$snmpRequest = new RouterOS\Request('/tool snmp-get address=10.9.8.7 community=public version=1 oid=1.3.6.1.2.1.2.2.1.6.1');

$snmpResponses = $client->sendSync($snmpRequest);
echo RouterOS\Script::escapeString($snmpResponses->getProperty('value'), true);

The API responses contains a !re response with “oid”, “type” and “value” properties that reflect the same things you see from terminal. The “value” property is the raw bytes, without any formatting. The RouterOS\Script::escapeString() method above converts it to a script/terminal format, with the second argument “true” encoding all bytes, to produce the formatting you’re after, i.e. “\58\10\8C\0D\8B\00”.

Thanks for answering. The code looks like this:

use PEAR2\Net\RouterOS;
require_once( dirname( __FILE__ ) . "/PEAR2_Net_RouterOS-1.0.0b6/src/PEAR2/Autoload.php" );

$client = new RouterOS\Client( '177.xx.xx.x', 'user', 'pass' ); //How to inform the port?
$snmpRequest = new RouterOS\Request('/tool snmp-get address=10.5.22.3 community=public version=1 oid=1.2.840.10036.1.1.1.1.5');

$snmpResponses = $client->sendSync($snmpRequest);
echo RouterOS\Script::escapeString($smpResponses->getProperty('value'), true);

But it gives the following error:

Fatal error: Call to a member function getProperty() on a non-object in /var/www/ssh3.php on line 19

If I give var_dump in $snmpRequest I have the following output:

object(PEAR2\Net\RouterOS\Request)#6 (4) {
  ["_command":"PEAR2\Net\RouterOS\Request":private]=>
  string(14) "/tool/snmp-get"
  ["_query":"PEAR2\Net\RouterOS\Request":private]=>
  NULL
  ["attributes":protected]=>
  array(4) {
    ["address"]=>
    string(9) "10.5.22.3"
    ["community"]=>
    string(6) "public"
    ["version"]=>
    string(1) "1"
    ["oid"]=>
    string(23) "1.2.840.10036.1.1.1.1.5"
  }
  ["_tag":"PEAR2\Net\RouterOS\Message":private]=>
  NULL
}

And if I give var_dump in $snmpResponses I have the following output:

object(PEAR2\Net\RouterOS\ResponseCollection)#7 (8) {
  ["responses":protected]=>
  array(2) {
    [0]=>
    object(PEAR2\Net\RouterOS\Response)#4 (4) {
      ["unrecognizedWords":protected]=>
      array(0) {
      }
      ["_type":"PEAR2\Net\RouterOS\Response":private]=>
      string(3) "!re"
      ["attributes":protected]=>
      array(3) {
        ["oid"]=>
        string(23) "1.2.840.10036.1.1.1.1.5"
        ["type"]=>
        string(12) "octet-string"
        ["value"]=>
        string(6) "ÜŸÛ˜~ä"
      }
      ["_tag":"PEAR2\Net\RouterOS\Message":private]=>
      NULL
    }
    [1]=>
    object(PEAR2\Net\RouterOS\Response)#5 (4) {
      ["unrecognizedWords":protected]=>
      array(0) {
      }
      ["_type":"PEAR2\Net\RouterOS\Response":private]=>
      string(5) "!done"
      ["attributes":protected]=>
      array(0) {
      }
      ["_tag":"PEAR2\Net\RouterOS\Message":private]=>
      NULL
    }
  }
  ["responseTypes":protected]=>
  array(2) {
    [0]=>
    string(3) "!re"
    [1]=>
    string(5) "!done"
  }
  ["responseTags":protected]=>
  array(2) {
    [0]=>
    NULL
    [1]=>
    NULL
  }
  ["responsesIndex":protected]=>
  array(0) {
  }
  ["propertyMap":protected]=>
  NULL
  ["position":protected]=>
  int(0)
  ["index":protected]=>
  NULL
  ["compareBy":protected]=>
  array(0) {
  }
}

Using PEAR2_Net_RouterOS-1.0.0b6

The port can be specified at the 4th argument (defaults to API’s default port 8728).

As for the error… oops, my bad… missed an “n” in the variable name when doing the call (it’s “snmp”, not “smp”). I’ll also fix it above for any copy&paste bypassing reader of this topic.

Fixed version:

use PEAR2\Net\RouterOS;
require_once( dirname( __FILE__ ) . "/PEAR2_Net_RouterOS-1.0.0b6/src/PEAR2/Autoload.php" );

$client = new RouterOS\Client( '177.xx.xx.x', 'user', 'pass', 8728);
$snmpRequest = new RouterOS\Request('/tool snmp-get address=10.5.22.3 community=public version=1 oid=1.2.840.10036.1.1.1.1.5');

$snmpResponses = $client->sendSync($snmpRequest);
echo RouterOS\Script::escapeString($snmpResponses->getProperty('value'), true);

But what a lack of attention mine, had not realized it. I love you boy, thanks for helping. I spent about 3 days trying to solve this problem. Now I’m going to continue my project. :laughing: :laughing:

God bless your life even more.