473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pySNMP: SNMPget example

I have recently installed pySNMP 3.3.2 and use Python 2.2.2. Thanks to
Peter Hansen, I succeeded to install pySNMP properly. I'm not
completely new to SNMP (I know the basics), but I'm new to Python and
pysnmp. While experimenting, I find some strange things. When using
pySNMP:

1) I can type: 'import pysnmp' or 'from pysnmp import *'

2) when using: 'from pysnmp import role' (found on
http://pysnmp.sourceforge
..net/examples/2.x/snmpget.html), I get the message 'ImportError:
cannot
import name role'. The same applies for 'from pysnmp import session'
or 'from pysnmp import v1' , but 'from pysnmp import proto' seems to
work.

3) A general question: how can I get a list of what I can type after
the 'from
pysnmp import ...'

4) How can I use: 'from snmpget import snmpget'. It does not accept
this.

5) Anyone has a simple example for the following application: I have a
cable
modem (which has an SNMP agent inside). I want to make a script where
I can
do SNMPgets (and later SNMPSet and SNMPwalk).

6) Where can I find a simple description on how to use 'snmpget'. I
cannot find
anything. I would like to write sth like snmpget(IP, OID)

7) What is the difference between snmpget and getrequest in pysnmp?

Any input is appreciated...

Thanks in advance,

Wim
Jul 18 '05 #1
3 21367
> 2) when using: 'from pysnmp import role' (found on
http://pysnmp.sourceforge
.net/examples/2.x/snmpget.html), I get the message 'ImportError:
You seems to use pysnmp 2.x API which differs from the latest 3.x branch
(though, a compatibility layer exists in 3.x distribution). That's why
I suggest you looking at the 3.x docs and examples at:

http://pysnmp.sourceforge.net/docs/3.x/index.html
3) A general question: how can I get a list of what I can type after
the 'from
pysnmp import ...'
dir(<module>) may help but in this case I'd better see an example.
4) How can I use: 'from snmpget import snmpget'. It does not accept
this.
There is no such module as snmpget in pysnmp.
5) Anyone has a simple example for the following application: I have a
cable
modem (which has an SNMP agent inside). I want to make a script where
I can
do SNMPgets (and later SNMPSet and SNMPwalk).
Python 1.5.2 (#3, Aug 25 1999, 19:14:24) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
from pysnmp.proto import v1
from pysnmp.proto.api import generic
from pysnmp.mapping.udp import role
req = v1.GetRequest()
req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)])
tr = role.manager(('router-1.glas.net', 161))
(answer, src) = tr.send_and_receive(req.encode())
rsp = v1.GetResponse()
rsp.decode(answer)
vars = rsp.apiGetPdu().apiGetVarBind()
print vars [('.1.3.6.1.2.1.1.1.0', OctetString('Cisco Internetwork Operating System
Software\015\012IOS (tm) 5400 Software(C5400-JS-M), Version 12.2(11.8b),
MAINTENANCE INTERIM SOFTWARE\015\012 Copyright (c) 1986-2002 by cisco
Systems, Inc.\015\012 Compiled Tue 30-Jul-02 19:02 by pwade'))]

7) What is the difference between snmpget and getrequest in pysnmp?


The only difference is the SNMP request object (GetRequest vs GetNextRequest)
you create when building SNMP message.

-ilya
Jul 18 '05 #2
I'd suggest you to refer to "high-level" API documentation at
http://pysnmp.sourceforge.net/docs/3.x/ for getting used to
basic operations on SNMP objects (such as apiGetPdu(), apiSetVarBind()).

Also, note, that pysnmp s/w (the third branch) has been closely aligned
with the APIs introduced by SNMP RFCs, so reading these RFCs may be
helpful too.

If you got more specific questions, please, let me know.

-ilya

WIWA <wi*********@skynet.be> wrote:
Thanks Ilya, This has been very helpful. I'm able to get data out of my 'device
under test'. I must be honnest and say that I understand the sample code, but could
not write or produce it myself. How do you know e.g that
req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)]) can be
written? I've read through the documentation and could not find
anything similar. Of course, I could overlook it. Isn't there a tutorial out there that summarizes pysnmpv3 and gives
examples of snmpget, snmpset, snmpwalk, etc... Thanks in advance for helping me out. Regards, Wim

Ilya Etingof <il**@cray.glas.net> wrote in message news:<be**********@news.rol.ru>...
> 2) when using: 'from pysnmp import role' (found on
> http://pysnmp.sourceforge
> .net/examples/2.x/snmpget.html), I get the message 'ImportError:


You seems to use pysnmp 2.x API which differs from the latest 3.x branch
(though, a compatibility layer exists in 3.x distribution). That's why
I suggest you looking at the 3.x docs and examples at:

http://pysnmp.sourceforge.net/docs/3.x/index.html
> 3) A general question: how can I get a list of what I can type after
> the 'from
> pysnmp import ...'


dir(<module>) may help but in this case I'd better see an example.
> 4) How can I use: 'from snmpget import snmpget'. It does not accept
> this.


There is no such module as snmpget in pysnmp.
> 5) Anyone has a simple example for the following application: I have a
> cable
> modem (which has an SNMP agent inside). I want to make a script where
> I can
> do SNMPgets (and later SNMPSet and SNMPwalk).


Python 1.5.2 (#3, Aug 25 1999, 19:14:24) [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from pysnmp.proto import v1
>>> from pysnmp.proto.api import generic
>>> from pysnmp.mapping.udp import role
>>> req = v1.GetRequest()
>>> req.apiGetPdu().apiSetVarBind([('1.3.6.1.2.1.1.1.0', None)])
>>> tr = role.manager(('router-1.glas.net', 161))
>>> (answer, src) = tr.send_and_receive(req.encode())
>>> rsp = v1.GetResponse()
>>> rsp.decode(answer)
>>> vars = rsp.apiGetPdu().apiGetVarBind()
>>> print vars

[('.1.3.6.1.2.1.1.1.0', OctetString('Cisco Internetwork Operating System
Software\015\012IOS (tm) 5400 Software(C5400-JS-M), Version 12.2(11.8b),
MAINTENANCE INTERIM SOFTWARE\015\012 Copyright (c) 1986-2002 by cisco
Systems, Inc.\015\012 Compiled Tue 30-Jul-02 19:02 by pwade'))]
>>>

> 7) What is the difference between snmpget and getrequest in pysnmp?


The only difference is the SNMP request object (GetRequest vs GetNextRequest)
you create when building SNMP message.

-ilya

Jul 18 '05 #3
> 1) Instead of writing '1.3.6.1.2.1.69.1.3.1', I would also like to be
able to write 'docsDevSwServer'. Any idea how I can do that?


The right way is to use a MIB parser (for labels-to-oids translation) which
is not a part of pysnmp. Try looking at Python backend to libsmi. If you
expect to query just a small and definite set of OIDs, an alternative would be
to hardcode labels-to-oid mapping somewhere in your script.

-ilya
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Krzysztof | last post by:
Hello, I noteced a weird problem with php snmpget. When I get two different consecutive queries from Cisco box (actualy, any box) and if the first returned value is not empty, but the second one...
1
by: Krzysztof | last post by:
No one could answer my question lately, so maybe today I will have some luck :-) Here we go again: I noteced a weird problem with php snmpget. When I get two different consecutive queries from...
0
by: WIWA | last post by:
Hi, I have installed pySNMP. I want to make an application where I read out all the OIDs of a MIB of a particular device. In other words, I want to do an SNMPwalk for a certain MIB. I can do...
2
by: Axel Scheepers | last post by:
Hi All, Python is so great. I've been creating a small set of objects to get some stats from our adsl routers. So far it works great and fast. However, in the shell script I created over a year...
4
by: Roy Smith | last post by:
There's been some talk recently about the relative speeds of the various python SNMP libraries. I just did a little benchmarking, and got some surprising results. I downloaded pysnmp-3.4.2 and...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
5
by: relaxedrob | last post by:
Hi All! I ran the following w3c example through my WSDL parser (SOA Editor from Cape Clear): http://www.w3.org/TR/wsdl#_rpcexample It told me that there were a bunch of erros about no...
11
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html...
3
by: rob.audenaerde | last post by:
I'm trying to monitor about 250 devices with SNMP, using PySNMP version 4. I use the threading.Thread to create a threadpool of 10 threads, so devices not responding won't slow down the monitoring...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.