An example for pysnmp

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData('public', mpModel=0),
           UdpTransportTarget(('192.168.1.1', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('1.3.6.1.4.1.8886.1.1.1.1.0')))
)

if errorIndication:
    print(errorIndication)
elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
                        errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

 

posted @ 2018-12-27 14:53  redstar9451  阅读(219)  评论(0)    收藏  举报