【发布时间】:2021-04-02 16:02:52
【问题描述】:
我正在尝试通过 pysnmp 获取 IF-MIB 值,并且在此 OID 中当前不存在此类对象。但是,我使用的代码与示例代码非常相似,所以我不确定出了什么问题。任何人都可以看到这个问题吗? 1.3.6.1.2.1.2.2.1.6应该是获取IF地址(http://oid-info.com/get/1.3.6.1.2.1.2.2.1.6)
from pysnmp.hlapi import *
from pysnmp.smi import builder, view
# snmp.live.gambitcommunications.com
# demo.snmplabs.com
# snmpsim.try.thola.io
# localhost
MIB_VIEW_CONTROLLER = view.MibViewController(builder.MibBuilder())
g = getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('127.0.0.1', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.6')),
lookupNames=True, lookupValues=True)
errorIndication, errorStatus, errorIndex, varBinds = next(g)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
print("hello")
for varBind in varBinds:
print(type(varBind))
print(' = '.join([x.prettyPrint() for x in varBind]))
【问题讨论】:
标签: python networking snmp pysnmp