pysnmp4.4和Python 2.7 bulkCmd输出不包括子OID

2024-10-08 19:29:28 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我不熟悉Python和PySNMP。我试图将网络设备列表传递给bulkCmd,以获取所有物理接口的信息。在

目前它只收集第一个接口,然后移动到列表中的下一个网络设备。我用字典法和maxCalls进行了修改,重复了一下,但没有任何区别。在

我已经成功地轮询了所有接口时,发送一个单一的bulkCmd到单个网络设备。在

代码:

from pysnmp.hlapi import *

routers = ["router1", "router2"]

#adds routers to getCmd and bulkCmd
def snmpquery (hostip):

    errorIndication, errorStatus, errorIndex, varBinds = next (
        bulkCmd(SnmpEngine(),
            CommunityData('communitystring'),
            UdpTransportTarget((hostip, 161)),
            ContextData(),
            0, 50,  
            ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
            ObjectType(ObjectIdentity('IF-MIB', 'ifAlias')),
            ObjectType(ObjectIdentity('IF-MIB', 'ifOperStatus')),
            lexicographicMode=True
        )
    )

    # Check for errors and print out results
    if errorIndication:
        print(errorIndication)

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


# calls snmpquery for all routers in list
for router in routers:
    snmpquery(router)

输出:

^{pr2}$

Tags: andinforif网络设备printroutersobjecttype
1条回答
网友
1楼 · 发布于 2024-10-08 19:29:28

您可以在程序确认的文本视图上调用setCustomTitle()
例如:

TextView tv = new TextView(this);
tv.setText("Title Here");

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(tv);

相关问题 更多 >

    热门问题