天天看点

snmp query with python

 snmp query with python

#!/usr/bin/env python  

import netsnmp 

class Snmp(object): 

    """ A basic SNMP session""" 

    def __init__(self, 

                 oid = "sysDescr", 

                 Version = 2, 

                 DestHost = "localhost", 

                 Community = "public"): 

        self.oid = oid 

        self.version   = Version 

        self.destHost  = DestHost 

        self.community = Community 

    def query(self): 

        """Creates SNMP query session""" 

        try: 

            result = netsnmp.snmpwalk(self.oid, 

                                  Version   = self.version, 

                                  DestHost  = self.destHost, 

                                  Community = self.community) 

        except Exception,err: 

            print err 

            result = None 

        finally: 

            print  result 

snmp=Snmp() 

snmp.query() 

本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1161323,如需转载请自行联系原作者