[Tutor] Simple Python SNMP ping?
leam hall
leamhall at gmail.com
Fri Aug 16 16:38:09 CEST 2013
One of the things I forgot to mention is that my host is using Python 2.4
and net-snmp 5.3; both packaged by a major North American Linux vendor. :)
So there doesn't seem to be a native net-snmp tool set for these versions.
I'll poke around and see what else can be done.
Thanks!
On Fri, Aug 16, 2013 at 12:06 AM, Chris Down <chris at chrisdown.name> wrote:
> 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
>
--
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130816/07a3a164/attachment.html>
More information about the Tutor
mailing list