pysnmp实现walk
from pysnmp.hlapi import *
def walk(ip, oid):
res=[]
for (errorIndication,errorStatus,errorIndex,varBinds) in nextCmd(SnmpEngine(),
CommunityData('123'), UdpTransportTarget((ip, 161)), ContextData(),
ObjectType(ObjectIdentity(oid)).addMibSource('C:/Users/22589/Desktop/urls/dist/MIBs', 'pysnmp_mibs'),lexicographicMode=False):
if errorIndication:
print(errorIndication, file=sys.stderr)
break
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'),
file=sys.stderr)
break
else:
for varBind in varBinds:
#print(varBind)
res.append(str(varBind))
return res