pySNMP: SNMPget example
wim_wauters at skynet.be
Mon Jul 14 20:52:36 CEST 2003
This has been very helpful. I'm able to get data out of my 'device
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([('188.8.131.52.184.108.40.206.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.
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:
> > 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([('220.127.116.11.18.104.22.168.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
> [('.22.214.171.124.126.96.36.199.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.
More information about the Python-list