How to convert a snmp-returned mac address?

I am using an snmp node to query a network device. One node returns a value that shows in a debug node as 'OctetString'.
Is there a node object I can use to convert this to an ascii string?


You haven't supplied any flow example of what you are doing, so just a guess here... but have you tried searching for "OctetString" in the forum? I did and see a possible solution, or part of one at least.

Im using node-red-snmp-node to connect to a router and query an OID which returns a NIC MAC address in a format of OctetString. My shell script that converts it to ascii needs its node-red counterpart. I looked at node-red-contrib-buffer-parser but I have not been able to decipher all of the options to get what I am looking for.

As it is, the OcteltString that is returned is undeciperable in a debug node. How to progress?

If you have a script that does what you need and if it is in javascript, or you can Google for something like it, perhaps put it in a function node.

Post up the outputof a debug node from the returned string - and also the real mac address in standard notation so we can see what is happening

  • MAC Adresses are decoded with .toString('hex')


Here is the output from the debug node:

Properly formatted by an snmp client program, it is:
Name/OID: ubntWlStatApMac.1; Value (OctetString): 68-D7-9A-8D-4B-96

Would I use the .toString('hex') in a function node?

Hi yes - something basic like (assuming you only have one value returned)

msg.payload[0].value = msg.payload[0].value.toString("hex");

It certainly brings back what appears to be a strange value which matches that in the object, but .toString('hex') does not appear to convert anything.

sorry can you cut/paste the actual value of the whole payload object here as a code block (using the </> button above - hover over the right hand end of the payload line

I'm running on the same issue while querying network devices.
A copy of the value shows exactly the same information zubenubi posted on image, a value string with strange characters:


If I do a query using a snmpwalk from the linux console, I'm getting a readable "Hex-STRING":

iso. = Hex-STRING: 48 57 54 43 AD A1 54 9A

If I convert the string to a buffer, just some chars at the beginning are ok:


The very first bytes are ok (if converted to HEX), but not the last ones, and has more bytes (14) than expected (8).

Here is the debug output:


I think it's a bug at the snmp get node, giving the response value as "OctetString" while (snmpwalk reports a Hex-String).
Looking into the value length, says that is 8, which is ok.
But looking into the char value for each character, looks like high values (above 128) are reported as 253 (xFD) and the real value has been lost:

msg.payload[0].value.toString("hex") =


Values reported as 253 (xFD) should be xAD, xA1 and x9A respectively. All the others are OK.

Hoping that the community can help to identify the difference between the 2 nodes. snmp node going after the specific oid returns:


When I use the snmp-table node: this is what is returned:


In the latter case, the SSID oid is not converted to ascii, which I can actually understand.

Is this an issue for node-red-snmp-node devs?


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.