如何在AsynCommandGenerator中进行多个GETNEXT查询?

时间:2013-01-29 06:42:06

标签: python pysnmp

#!/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中只有一个元素。我怎么能得到所有这些?

1 个答案:

答案 0 :(得分:1)

要执行另一个GETNEXT,cbFun()应该通过返回True来请求。否则,AsynCommandGenerator将不会执行下一个GETNEXT。

请参阅relevant example