2016-01-06 138 views
0

我想爲pysnmp提供基礎oid,例如1.3.6.1.2.1.2.2.1.8,並且能夠獲取它下面的所有子項,例如1.3.6.1.2.1.2.2.1.8.1 - 1.3.6.1.2.1.2.2.1.8.n,而不會轉到1.3.6.1.2.1.2.2.1.9。我想知道如何去做這件事?我也嘗試過GETNEXT,但不知道如何去實現我想要的。另一個問題是pysnmp似乎試圖解決與它相關聯的mib的oid,我該如何關閉此功能?我目前正在使用最新版本的pysnmp。pysnmp獲取子樹並且不解析針對mib名稱的oid

回答

0

嘗試使這兩個lookupMib=FalselexicographicMode=False到nextCmd()或bulkCmd():

from pysnmp.hlapi import * 

for errorIndication, errorStatus, \ 
    errorIndex, varBinds in bulkCmd(
     SnmpEngine(), 
     CommunityData('public'), 
     UdpTransportTarget(('demo.snmplabs.com', 161)), 
     ContextData(), 
     0, 50, # GETBULK specific: request up to 50 OIDs in a single response 
     ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.8')), 
     lookupMib=False, lexicographicMode=False): 

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