我有以下代码可以正常运行 snmp,但是当我尝试使用接口号循环“t”提取设备(wlc)上的所有序列号时,它与打印功能很好,但是当它将它保存到变量中时vaBinds[3][1] 它只保存最后一个。每次循环时如何保存所有变量值。
不确定我的问题是否有意义,但请尽可能提供帮助。先感谢您。
for t in range(1, 3):
t = str(t)
t.strip()
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData(item, mpModel=0 or 1),
UdpTransportTarget((str(i), 161), timeout=0, retries=0),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)), # 0
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)), # 1
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), # 2
ObjectType(ObjectIdentity('ENTITY-MIB', 'entPhysicalSerialNum', t)), # 3
ObjectType(ObjectIdentity('ENTITY-MIB', 'entPhysicalModelName', t))), # 4
)
# print(varBinds[3][1])
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(i),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) # error exceptions
else:
for varBind in varBinds:
B = varBinds[0]