pySNMP: SNMPget example

Ilya Etingof ilya at
Mon Jul 14 09:52:27 CEST 2003

> 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([('', None)])
>>> tr = role.manager(('', 161))
>>> (answer, src) = tr.send_and_receive(req.encode())
>>> rsp = v1.GetResponse()
>>> rsp.decode(answer)
>>> vars = rsp.apiGetPdu().apiGetVarBind()
>>> print vars
[('.', 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 mailing list