from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
# varBindTable是个list,元素的个数可能有好多个。它的元素也是list,这个list里的元素是ObjectType,个数只有1个。
errorIndication, errorStatus, errorindex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('127.0.0.1', 161)),
'1.3.6.1.2.1.25.6.3.1',
)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorindex and varBinds[int(errorindex) - 1][0] or '?'
)
)
for varBindTableRow in varBindTable:
for item in varBindTableRow:
print(item)