Problems with SNMP

Hello!

I’m trying to solve a problem with SNMP to map computers and switch
ports. The deal here is, for each computer pluged in my switch,
associate its MAC address with the port of the switch.

I try to discover at http://snmplib.rubyforge.org/ but I just can’t
figure out a way to do that. I already can list all ports, given the
examples at the documentation, but I need the MAC address of each
computer.

At the switch web interface, I already can find the MAC address of each
computer, so it’s working fine.

If anybody can help me with this task I really appreciate it.

Regards,

Rocir S.

Rocir, you should first check if your switch supports this
functionality. If
it does I’d try to do an snmpwalk through the complete table to find an
OID
providing a list of known mac addresses, which will most likely be
grouped
by interface (port).

This link may come in handy: http://www.oid-info.com/index.htm

Regards


Nicolás Brailovsky

2009/10/1 Rocir S. [email protected]

Hi, Nicolás.

Thanks for the reply. My switch works fine with SNMP. It’s 3com Baseline
Switch 2226 Plus. My doubt it’s about the ruby code to find the MAC
address of each computer “pluged” in my switch. I can figure out some
examples at the doc page of this lib. But when I just try to get the
ifPhysAddress, the application raises an error and I don’t know why.

Here is the code:


require ‘snmp’

ifTable_columns = [“ifIndex”, “ifDescr”, “ifInOctets”, “ifOutOctets”,
“ifPhysAddress”]
SNMP::Manager.open(:Host => ‘xxx.xxx.xxx.xxx’) do |manager|
manager.walk(ifTable_columns) do |row|
row.each { |vb| print “\t#{vb.value}” }
puts
end
end


I just added the ifPhysAddress to the example in the site. If I just
remove the ifPhysAddress, it works fine.

Nicolás Brailovsky wrote:

Rocir, you should first check if your switch supports this
functionality. If
it does I’d try to do an snmpwalk through the complete table to find an
OID
providing a list of known mac addresses, which will most likely be
grouped
by interface (port).

This link may come in handy: http://www.oid-info.com/index.htm

Regards


Nicolás Brailovsky

2009/10/1 Rocir S. [email protected]

When I just add the ifPhysAddress, the application just exists, with out
any message.

I know the switch supports what I want because at the web interface I
can see a image that shows all the pluged machines and I can see the MAC
address of each one.

What I just need is to get those mapings into ruby code. My app need
that information but I can’t just figure out a way to do that.

Nicolás Brailovsky wrote:

2009/10/1 Rocir S. [email protected]

Hi, Nicolás.

Thanks for the reply. My switch works fine with SNMP. It’s 3com Baseline
Switch 2226 Plus.

Problem is though it may support SNMP protocol it sure won’t support all
the
options (OIDs) the RFC defines. Some switches do support listing known
devices, some don’t.

My doubt it’s about the ruby code to find the MAC
address of each computer “pluged” in my switch. I can figure out some
examples at the doc page of this lib. But when I just try to get the
ifPhysAddress, the application raises an error and I don’t know why.

My experience with SNMP si mostly in C++, not Ruby, but it may be
helpful to
know which exception is your application raising. It may be because the
OID
is not supported (no such instance exception) or because it’s not
defined in
your code. To assert if the switch does support this OID try using
snmpget
from console, not from within a program.

BTW, if I remember correctly ifPhysAddress will give you the iface’s mac
internal to the switch, not the mac of the device in that port (there
may be
many known macs per port too).

Regards,

Nicolás Brailovsky - http://nicolasb.com.ar/

2009/10/1 Rocir S. [email protected]

Hi, Nicolás.

Thanks for the reply. My switch works fine with SNMP. It’s 3com Baseline
Switch 2226 Plus.

Problem is though it may support SNMP protocol it sure won’t support all
the
options (OIDs) the RFC defines. Some switches do support listing known
devices, some don’t.

My doubt it’s about the ruby code to find the MAC
address of each computer “pluged” in my switch. I can figure out some
examples at the doc page of this lib. But when I just try to get the
ifPhysAddress, the application raises an error and I don’t know why.

My experience with SNMP si mostly in C++, not Ruby, but it may be
helpful to
know which exception is your application raising. It may be because the
OID
is not supported (no such instance exception) or because it’s not
defined in
your code. To assert if the switch does support this OID try using
snmpget
from console, not from within a program.

BTW, if I remember correctly ifPhysAddress will give you the iface’s mac
internal to the switch, not the mac of the device in that port (there
may be
many known macs per port too).

Regards,

Nicolás Brailovsky - http://nicolasb.com.ar/

2009/10/1 Rocir S. [email protected]

When I just add the ifPhysAddress, the application just exists, with out
any message.

You’ll have to find what’s the exception by capturing it yourself then,
there’s no way my psychic powers can reach that far.

I know the switch supports what I want because at the web interface I
can see a image that shows all the pluged machines and I can see the MAC
address of each one.

Doesn’t mater, the web interface may show it but that doesn’t mean SNMP
supports this functionality. Reffer to the different RFCs for SNMP and
check
if it’s supported using another SNMP tool, like those from netsnmp.

Regards

Nicolás Brailovsky - http://nicolasb.com.ar/

When I run the code that I sent, the output is:

__
1 Ethernet Port on unit 1, port 1 4470 89926 >Exit code: 0
__

At the first interation, it just exits when try to print the
ifPhysAddress information.

About the switch, do you have any idea how can I “test” it? You told me
to use snmpget but it requires an OID. I don’t know how can I discover
what OID I can use.

I’m really new with SNMP and I just need that functionality in my app,
because of that I’mhaving some problems.

Thank you for your help.

Nicolás Brailovsky wrote:

2009/10/1 Rocir S. [email protected]

When I just add the ifPhysAddress, the application just exists, with out
any message.

You’ll have to find what’s the exception by capturing it yourself then,
there’s no way my psychic powers can reach that far.

I know the switch supports what I want because at the web interface I
can see a image that shows all the pluged machines and I can see the MAC
address of each one.

Doesn’t mater, the web interface may show it but that doesn’t mean SNMP
supports this functionality. Reffer to the different RFCs for SNMP and
check
if it’s supported using another SNMP tool, like those from netsnmp.

Regards

Nicolás Brailovsky - http://nicolasb.com.ar/

2009/10/1 Rocir S. [email protected]

When I run the code that I sent, the output is:

__
1 Ethernet Port on unit 1, port 1 4470 89926 >Exit code: 0
__

At the first interation, it just exits when try to print the
ifPhysAddress information.

All logic says it either throws an exception or finishes correctly. It
may
be the lib you use is not throwing when it should but I’m not familiar
with
the SNMP lib you’re using. Where did you get the identifier
“ifPhysAddress”?
Did you define its OID somewhere?

About the switch, do you have any idea how can I “test” it?

Use snmpget, snmpwalk and snmpbulk* from libnetsnmp utils.

You told me
to use snmpget but it requires an OID. I don’t know how can I discover
what OID I can use.

ifPhysAddress is just a user friendly name of a numerical OID (in the
form
of 1.3.6.1…). Check the link I posted before, you can find a lot of
OIDs
there.

I’m really new with SNMP and I just need that functionality in my app,
because of that I’mhaving some problems.

I’d recomend reading some RFCs and manuals, get used to the protocol and
they way it works and then write an application using it, not otherwise.

Regards

Not that I think snmplib isn’t good, but maybe it’ll be easier to
start with a simpler library? I’ve had alot of luck with s2nmp.

It’s a japanese library, but google translate gives enough info to
figure it out
http://translate.google.com/translate?hl=en&sl=ja&u=http://members.at.infoseek.co.jp/m6809/index-j.html&ei=5erJSoD2KaLOtAP805yiBQ&sa=X&oi=translate&resnum=1&ct=result&prev=/search%3Fq%3Ds2nmp%26hl%3Den%26safe%3Dactive%26client%3Dfirefox-a%26rls%3Dcom.ubuntu:en-US:unofficial%26hs%3DbQn

Here’s how you would walk the tree (list any and all OIDs under your
starting point) using it:

#!/usr/bin/ruby
require ‘socket’
require ‘s2nmp’

SNMP.new(“itlj2”).walk(“public”,[“1.”]){|i| puts i[0]}

Nice and easy way to find what OIDs you’re looking for.

–Kyle