pySNMP: SNMPget example
wim_wauters at skynet.be
Tue Jul 15 17:03:02 CEST 2003
I was wondering if you could help me: I want to create an SNMP
application and would need the following:
1) Instead of writing '220.127.116.11.18.104.22.168.3.1', I would also like to be
able to write 'docsDevSwServer'. Any idea how I can do that?
2) I have downloaded some MIBs. How can I make my program aware of the
existence of these MIBs. Basically I want to write a program that
allows the user to browse to these MIBs and then import them into a
GUI. Any ideas?
Ilya Etingof <ilya at cray.glas.net> wrote in message news:<bf07n8$i1b$1 at news.rol.ru>...
> 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.
> WIWA <wim_wauters at 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([('22.214.171.124.126.96.36.199.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 <ilya at cray.glas.net> wrote in message news:<betnfr$dqj$1 at 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([('188.8.131.52.184.108.40.206.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
> >> [('.220.127.116.11.18.104.22.168.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
More information about the Python-list