簡體   English   中英

pysnmp獲取子樹並且不針對mib名稱解析oid

[英]pysnmp get subtree and do not resolve oid against mib name

我想為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似乎試圖將oid解析為與其關聯的mib,我該如何關閉此功能? 我當前正在使用最新版本的pysnmp。

嘗試將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]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM