私はpythonを初めて使用しています。私はpysnmpの使い方を理解しようとしています。pysnmp - nextCmd - 次の要素を取得していません
私は次のことを試してみました:
import asyncio
from pysnmp.hlapi.asyncio import *
from pysnmp import debug
@asyncio.coroutine
def run():
snmpEngine = SnmpEngine()
while True:
errorIndication, errorStatus, errorIndex, varBinds = yield from nextCmd(
snmpEngine,
CommunityData('public', mpModel=1),
UdpTransportTarget(('giga-int-2', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.31.1.1.1.1')),
lexicographicMode=False
)
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?')
)
else:
for varBind in varBinds:
for v in varBind:
print(' = '.join([x.prettyPrint() for x in v]))
snmpEngine.transportDispatcher.closeDispatcher()
asyncio.get_event_loop().run_until_complete(run())
私はいつも同じインターフェイスを取得結果。どうしましたか?なぜ次の要素を取得しないのですか?
SNMPv2-SMI::mib-2.31.1.1.1.1.1 = sc0
SNMPv2-SMI::mib-2.31.1.1.1.1.1 = sc0
SNMPv2-SMI::mib-2.31.1.1.1.1.1 = sc0
別のOIDを試してみてください。ここで
は、あなたのアイデアを与えるために私のテストされていないコードです。あなたのコードはうまくいくようですが、いつも同じデバイス名を照会しています –
私が達成したいのは、snmpwalk -v2c -cpublic giga-int-2 1.3.6.1.2.1.31.1.1.1と同じ出力です。 1 IF-MIB :: ifName.1 = STRING:sc0 IF-MIB :: ifName.2 = STRING:sl0 ... – Celio
この場合、OID 1.3.6.1.2.1.31.1.1.1.1をループする必要があります、1.3.6.1.2.1.31.1.1.1.2、1.3.6.1.2.1.31.1.1.1.3など、私は思う。 –