Getting arp table via snmp

Hi to the list,

I’m trying to get the ARP table from a switch via SNMP. Everything works
fine while reading IP addresses; but there’s a problem about reading MAC
addresses… Unknown characters and empty lines appear in MAC address’
part
like that:

[name=1.3.6.1.2.1.4.22.1.2.28.221.208.208.212, value=
E� (OCTET STRING)]

Where’s the problem?

Best Regards,

Pinar

ps: the script that i gather the output above is here:

require ‘snmp’
include SNMP

Manager.open(:Host => ‘xxx.xxx.xxx.xxx’) do |manager|
arpTable = ObjectId.new(“1.3.6.1.2.1.4.22.1.2”)
next_oid = arpTable
while next_oid.subtree_of?(arpTable)
response = manager.get_next(next_oid)
varbind = response.varbind_list.first
next_oid = varbind.name
puts varbind
end
end

On 7/5/06, pinar y [email protected] wrote:

[name=1.3.6.1.2.1.4.22.1.2.28.221.208.208.212, value=
E� (OCTET STRING)]

Where’s the problem?

The problem is that you have an OCTET STRING I have converted it into
readable form
with the code posted below, unfortunately I am not a MIB expert and
cannot
tell you how to see the IP addresses associated with the MAC
addresses.
Hope you find this useful anyway
#!/usr/bin/env ruby

require ‘rubygems’
require ‘snmp’
include SNMP

class OctetString
def to_hex
h=“”
each_byte{ |b| h << “%02x” % b }
h
end # def to_hex
end # class OctetString

Manager.open(:Host => ‘128.1.0.70’) do |manager|
arpTable = ObjectId.new(“1.3.6.1.2.1.4.22.1.2”)
next_oid = arpTable
while next_oid.subtree_of?(arpTable) do
response = manager.get_next(next_oid)
varbind = response.varbind_list.first
next_oid = varbind.name
value = varbind.value
case value
when OctetString
value = value.to_hex
end
puts “#{varbind.name.to_s} #{value}”

     end

end

<SNIPPed your code, contained in mine>

Cheers
Robert


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

I was pulling my hair about two days, that’s what i want now ! Many
thanks
to you =)

2006/7/5, Robert D. [email protected]: