Forum: Ruby Re: snmp error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-06-27 17:31
(Received via mailing list)
> the mac address is visualized as shown
>
> 1.3.6.1.2.1.2.2.1.6.1 ýg OCTET STRING
>
> instead of 0:10:83:fd:dd:67.
>
> How can I fix it?

The trouble is that you are printing the raw 6 byte string (note that
hex 67
is the ASCII code for a lower-case 'g')

So you just need to convert it into 12 hex digits:

    a = "\x00\x10\x83\xfd\xdd\x67"
    puts a.unpack("H*").first

Here's one way to add the colons:

    a = "\x00\x10\x83\xfd\xdd\x67"
    puts a.unpack("H2H2H2H2H2H2").join(":")
This topic is locked and can not be replied to.