#!/usr/bin/env python
#-*- coding: utf-8 -*-
from pysnmp.entity.rfc3413.oneliner import cmdgen
def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx):
print varBinds
def main():
ip = '127.0.0.1'
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.nextCmd(
cmdgen.CommunityData('mymypub')
cmdgen.UdpTransportTarget((ip, 161)),
'1.3.6.1.2.1.17.7.1.2.2.1.2')
#varBinds have about 200 elements
print varBinds
cmdGen = cmdgen.AsynCommandGenerator()
cmdGen.asyncNextCmd(
cmdgen.CommunityData('mymypub'),
cmdgen.UdpTransportTarget((ip, 161)),
((1,3,6,1,2,1,17,7,1,2,2,1,2),),
(cbFun, ip))
cmdGen.snmpEngine.transportDispatcher.runDispatcher()
#varBinds have 1 element
if __name__ == '__main__':
main()
我在CommandGenerator中获取所有元素。但我在AsynCommandGenerator中只有一个元素。我怎么能得到所有这些?
答案 0 :(得分:1)
要执行另一个GETNEXT,cbFun()应该通过返回True来请求。否则,AsynCommandGenerator将不会执行下一个GETNEXT。