# How to convert a snmp-returned mac address?

**URL:** <https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196>\
**Category:** General\
**Created:** [8 July 2021 23:10 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196 "2021-07-08T23:10:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [8 July 2021 23:10 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/1 "2021-07-08T23:10:50Z")

</div>

Hi,  
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?

Thanks

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [9 July 2021 00:45 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/2 "2021-07-09T00:45:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [9 July 2021 01:14 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/3 "2021-07-09T01:14:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [9 July 2021 03:01 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/4 "2021-07-09T03:01:02Z")

</div>

> [@zubenubi](#):
>
> My shell script that converts it to ascii needs its node-red counterpart

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.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [9 July 2021 03:52 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/5 "2021-07-09T03:52:31Z")

</div>

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')`

Craig

---

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [9 July 2021 14:18 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/6 "2021-07-09T14:18:14Z")

</div>

Here is the output from the debug node:  
[{"oid":"1.3.6.1.4.1.41112.1.4.5.1.4.1","type":4,"value":"hך�K�","tstr":"OctetString"}]

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?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 July 2021 14:56 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/7 "2021-07-09T14:56:46Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [9 July 2021 15:23 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/8 "2021-07-09T15:23:31Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/41b2906997440b613cf12d207d9fe8b64d733681.png)  
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 July 2021 16:15 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/9 "2021-07-09T16:15:45Z")

</div>

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  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3702436e09a95c356632841c4c87168e2b678db.png)

---

<div class="post-metadata">

**Author:** ![ramon-roca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ramon-roca/32/44904_2.png) [@ramon-roca](https://discourse.nodered.org/u/ramon-roca)\
**Post date:** [14 July 2021 15:54 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/10 "2021-07-14T15:54:07Z")

</div>

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:

```auto
[{"oid":"1.3.6.1.4.1.2011.6.128.1.1.2.43.1.3.4194324224.1","type":4,"value":"HWTC��T�","tstr":"OctetString"}]

```

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

```auto
iso.3.6.1.4.1.2011.6.128.1.1.2.43.1.3.4194324224.1 = 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:

```auto
msg.payload=Buffer.from(msg.payload[0].value);

```

```auto
[72,87,84,67,239,191,189,239,191,189,84,239,191,189]

```

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

---

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [14 July 2021 16:36 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/11 "2021-07-14T16:36:33Z")

</div>

Here is the debug output:

```auto
[{"oid":"1.3.6.1.4.1.41112.1.4.5.1.4.1","type":4,"value":"hך�K�","tstr":"OctetString"}]

```

---

<div class="post-metadata">

**Author:** ![ramon-roca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ramon-roca/32/44904_2.png) [@ramon-roca](https://discourse.nodered.org/u/ramon-roca)\
**Post date:** [17 July 2021 08:48 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/12 "2021-07-17T08:48:59Z")

</div>

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:

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

[72,87,84,67,253,253,84,253]

```

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

---

<div class="post-metadata">

**Author:** ![zubenubi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zubenubi/32/44576_2.png) [@zubenubi](https://discourse.nodered.org/u/zubenubi)\
**Post date:** [19 July 2021 22:10 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/13 "2021-07-19T22:10:34Z")

</div>

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

```auto
[{"oid":"1.3.6.1.4.1.41112.1.4.5.1.2.1","type":4,"value":"NCB","tstr":"OctetString"}]

```

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

```auto
{"1":{"1":5,"2":[78,67,66],"3":2,"4":[106,215,154,141,75,150],"5":-53,"6":43,"7":98,"8":-90,"9":58500000,"10":65000000,"11":[110,111,110,101],"12":2,"13":2,"14":20,"15":1}}

```

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?

TIA

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 September 2021 22:11 UTC](https://discourse.nodered.org/t/how-to-convert-a-snmp-returned-mac-address/48196/14 "2021-09-17T22:11:02Z")

</div>

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