Re: SNMP oid error



Hi,

The Ruby SNMP library isn't as smart as Net-SNMP at formating output
because it doesn't have any knowledge of the underlying MIB. The
actual format of the MAC address is just 6 bytes (octets) representing
each digit of the MAC. Try vb.value.inspect to see what I mean. You
need to do your own translation.

Try this instead of vb.value.to_s:

vb.value.unpack("H2H2H2H2H2H2").join(":")

You could even add a to_mac method to the OctetString class
(untested).

module SNMP
class OctetString
def to_mac
raise "Invalid MAC" unless self.length == 6
self.unpack("H2H2H2H2H2H2").join(":")
end
end
end

Hope that helps.

Cheers,

Dave

On Jun 25, 7:18 am, jc <jack.ciaba...@xxxxxxxxx> wrote:
Hi,

I'm using SNMP module into a simple script. I would like retrieve
interfaces MAC
addresses by using oid "1.3.6.1.2.1.2.2.1.6" :

+ using snmpwalk it works fine

snmpwalk -v 1 -r 1 -t 2 -c public 127.0.0.1 .1.3.6.1.2.1.2.2.1.6
IF-MIB::ifPhysAddress.1 = STRING: 0:10:83:fd:dd:67

+ using ruby

ifTable_columns = [ "1.3.6.1.2.1.2.2.1.6", ]
SNMP::Manager.open(:Host => "#{host}", :Version => :SNMPv1, :Community
=> 'public') do |manager|
manager.walk(ifTable_columns) do |row|
row.each { |vb| puts "#{vb.name.to_s} #{vb.value.to_s}
#{vb.value.asn1_type}"
end
end

1.3.6.1.2.1.2.2.1.6.1 ýÝg OCTET STRING

It shows ýÝg as MAC address. How can I fix it?

Thank you very much,
Jc

--
Posted viahttp://www.ruby-forum.com/.


.



Relevant Pages

  • Re: Detecting multiple hosts behind a single managed switch port
    ... Foundry and Cisco) via SNMP and return ports on those switches that ... have more than one end host connected (based on MAC addresses). ... would need to filter out ports that are connected to other managed ... This task is a bit tricky because on the Cisco, ...
    (comp.dcom.sys.cisco)
  • Re: Tips oder Warnungen =?iso-8859-1?Q?f=FCr?= Multifunktionsdrucker =?iso-8859-1?Q?
    ... man mit der Windows-Software noch so alles machen kann. ... dem Mac verfügbar? ... Brother MFC zwischenspeichern und anschl. ... Von obigen Unterschieden abgesehen (also Druckerfunktionalität per SNMP, ...
    (de.comp.sys.mac.misc)
  • Re: Getting MAC adress
    ... > I'm looking for a way to retrieve the number of interfaces and their MAC ... > adresses under HP-UX, AIX and Solaris. ... I would look into a perl script using snmp. ...
    (comp.sys.hp.hpux)
  • RE: Experts Guide regarding MAC Address of a remote machine.
    ... A possibility which I employed to this end in the distant past was to use SNMP to access the router supporting the subnet on which the PC resided, and scan its IP address table (which contains the Mac address and IP address in question). ...
    (microsoft.public.win32.programmer.networks)