我可以从命令行运行此命令:
snmpwalk -v3 -m +MY-MIB-ROOT -m +MY-MIB -l authPriv -u MYUSER -a SHA -A "XXXXXXXX" -x AES -X "XXXXXXXX" 1.2.3.4 .1.3.6.1.4.1.52330.6.1.2
我正在尝试使用 pysnmp 在 python 脚本中实现相同的命令:
import asyncio
from pysnmp.hlapi.v3arch.asyncio import *
from pysnmp.smi import builder, view, compiler
import logging
logging.basicConfig(level=logging.DEBUG)
# snmpwalk -v3 -m +MY-MIB-ROOT -m +MY-MIB -l authPriv -u MYUSER -a SHA -A "XXXXXXXX" -x AES -X "XXXXXXXX" 1.2.3.4 .1.3.6.1.4.1.52330.6.1.2
# Load MIBs
mibBuilder = builder.MibBuilder()
compiler.addMibCompiler(mibBuilder, sources=['file:///usr/share/snmp/mibs'])
mibViewController = view.MibViewController(mibBuilder)
loadedModules = mibBuilder.mibSymbols.keys()
print("loadedModules:", loadedModules)
async def run(varBinds):
snmpEngine = SnmpEngine()
while True:
print("A")
errorIndication, errorStatus, errorIndex, varBindTable = await bulkCmd(
snmpEngine,
UsmUserData(
'MYUSER',
'XXXXXXXX',
'XXXXXXXX',
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmAesCfb128Protocol,
),
await UdpTransportTarget.create(('1.2.3.4', 161)),
ContextData(),
0,
50,
*varBinds
)
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print(
f"{errorStatus.prettyPrint()} at {varBinds[int(errorIndex) - 1][0] if errorIndex else '?'}"
)
else:
for varBind in varBindTable:
oid = varBind.__getitem__(0)
print(oid)
varBinds = varBindTable
if isEndOfMib(varBinds):
break
return
asyncio.run(
run([ObjectType(ObjectIdentity('1.3.6.1.4.1.52330.6.1.2'))])
)
我收到此错误:
Ciphering services not available
我正在 Red Hat Enterprise Linux 版本 9.4 (Plow) 上的虚拟环境中运行脚本
$ pip list
Package Version
------------------ ---------
certifi 2024.8.30
charset-normalizer 3.3.2
idna 3.10
Jinja2 3.1.4
MarkupSafe 2.1.5
pip 24.2
ply 3.11
pyasn1 0.6.1
pycryptodomex 3.20.0
pysmi 1.5.0
pysnmp 7.1.4
requests 2.32.3
setuptools 53.0.0
urllib3 2.2.3
如果其他人遇到此问题,最新版本使用了加密包,因此在我安装后它可以工作:
pip install cryptography