Problems with SNMP

R

Rocir Santiago

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 Santiago
 
R

Rocir Santiago

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.
 
N

Nicolás Brailovsky

2009/10/1 Rocir Santiago said:
Hi, Nicol=E1s.

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 th=
e
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 t=
o
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 i=
n
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 b=
e
many known macs per port too).

Regards,
--=20
Nicol=E1s Brailovsky - http://nicolasb.com.ar/



Here is the code:

_________
require 'snmp'

ifTable_columns =3D ["ifIndex", "ifDescr", "ifInOctets", "ifOutOctets",
"ifPhysAddress"]
SNMP::Manager.open:)Host =3D> '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=E1s Brailovsky said:
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=E1s Brailovsky
- http://nicolasb.com.ar/
- http://monosinfinitos.com.ar/

2009/10/1 Rocir Santiago <[email protected]>
 
R

Rocir Santiago

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.
 
N

Nicolás Brailovsky

2009/10/1 Rocir Santiago said:
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 chec=
k
if it's supported using another SNMP tool, like those from netsnmp.



Regards
--=20
Nicol=E1s Brailovsky - http://nicolasb.com.ar/
 
R

Rocir Santiago

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.
 
N

Nicolás Brailovsky

2009/10/1 Rocir Santiago said:
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

--=20
Nicol=E1s Brailovsky - http://nicolasb.com.ar/
 
K

Kyle Schmitt

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=3Den&sl=3Dja&u=3Dht=
tp://members.at.infoseek.co.jp/m6809/index-j.html&ei=3D5erJSoD2KaLOtAP805yi=
BQ&sa=3DX&oi=3Dtranslate&resnum=3D1&ct=3Dresult&prev=3D/search%3Fq%3Ds2nmp%=
26hl%3Den%26safe%3Dactive%26client%3Dfirefox-a%26rls%3Dcom.ubuntu:en-US:uno=
fficial%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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top