[Tutor] Simple Python SNMP ping?

Chris Down chris at chrisdown.name
Fri Aug 16 06:06:33 CEST 2013


Hi Leam,

On 2013-08-14 15:21, leam hall wrote:
> Is there a way to do a simple check in Python to see if a remote host is
> listening on SNMP port 161/UDP?

"Simple" in this case could either mean technically simple (in which case, use
a socket with SOCK_DGRAM and wait for data) or implementationally simple (in
which case, use an SNMP library). I'd only recommend doing the latter.

Since UDP is stateless, you'll need to make sure that your destination replies
with something, which means you probably need to send a real SNMP request.
Since that's the case, you should really just use a real SNMP library (although
I fear that your meaning of "simple" was "not using an SNMP library", which is
really not simple at all.

net-snmp[0] can do this fairly trivially, anyway. The following works for me:

    >>> import netsnmp
    >>> var = netsnmp.Varbind('sysDescr.0')
    >>> netsnmp.snmpget(
    ...     var,
    ...     Version=2,
    ...     DestHost="localhost",
    ...     Community="pub",
    ... )
    ('OpenBSD',)

Best,

Chris

0: http://www.net-snmp.org/wiki/index.php/Python_Bindings
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130816/7c66f7d2/attachment.pgp>


More information about the Tutor mailing list