# Getting arp table via snmp

**URL:** <https://www.ruby-forum.com/t/getting-arp-table-via-snmp/97154>\
**Category:** Ruby\
**Created:** [July 5, 2006, 10:16am UTC](https://www.ruby-forum.com/t/getting-arp-table-via-snmp/97154 "2006-07-05T10:16:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pinar\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2bfe46/32.png) [@pinar\_y](https://www.ruby-forum.com/u/pinar_y)\
**Post date:** [July 5, 2006, 10:16am UTC](https://www.ruby-forum.com/t/getting-arp-table-via-snmp/97154/1 "2006-07-05T10:16:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pinar\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2bfe46/32.png) [@pinar\_y](https://www.ruby-forum.com/u/pinar_y)\
**Post date:** [July 5, 2006, 2:26pm UTC](https://www.ruby-forum.com/t/getting-arp-table-via-snmp/97154/2 "2006-07-05T14:26:36Z")

</div>

On 7/5/06, pinar y [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![pinar\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2bfe46/32.png) [@pinar\_y](https://www.ruby-forum.com/u/pinar_y)\
**Post date:** [July 5, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/getting-arp-table-via-snmp/97154/3 "2006-07-05T15:07:33Z")

</div>

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

2006/7/5, Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
