pysnmp setCmd似乎没有设置对象,但没有错误

2024-06-30 17:02:19 发布

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

我对SNMP和pysnmp不熟悉。我已经编写了一些代码来为一些mib设置一些值,但它似乎不起作用。我正在使用的oid是在一个我们不再使用的旧perl脚本中工作的,所以我知道我有正确的oid。你知道吗

我错过了什么?我没有头发要拔了!:)19

示例代码:

#!/usr/local/bin/python2.7

from pysnmp.hlapi import * # For SNMP

errorIndication, errorStatus, errorIndex, varBinds = next(
      setCmd(SnmpEngine(),
             CommunityData("myCommunity", mpModel=1),
             UdpTransportTarget(("remotedevice.com",161)),
             ContextData(),
             ObjectType(ObjectIdentity(".1.3.6.1.4.1.4115.1.8.1.10.5.1.0"), Integer(3)) ,
             ObjectType(ObjectIdentity(".1.3.6.1.4.1.4115.1.8.1.10.5.2.0"), OctetString("192.168.1.1")) ,
             ObjectType(ObjectIdentity(".1.3.6.1.4.1.4115.1.8.1.10.5.3.0"), OctetString("backup")) ,
             ObjectType(ObjectIdentity(".1.3.6.1.4.1.4115.1.8.1.10.5.6.0"), Integer(3)) )
)

print(errorIndication)
print(errorStatus)
print(errorIndex)
for bind in varBinds:
    print(bind)

输出:

None
0
0
SNMPv2-SMI::enterprises.4115.1.8.1.10.5.1.0 = 3
SNMPv2-SMI::enterprises.4115.1.8.1.10.5.2.0 = 192.168.1.1
SNMPv2-SMI::enterprises.4115.1.8.1.10.5.3.0 = backup
SNMPv2-SMI::enterprises.4115.1.8.1.10.5.6.0 = 3

Tags: 代码integersnmpsmioidprintpysnmpobjecttype
1条回答
网友
1楼 · 发布于 2024-06-30 17:02:19

看起来SET命令实际上成功了。您得到的输出是您的SNMP代理所需要的@远程设备.com已报告。所以这些应该是这些OID的新值。你知道吗

是什么让你认为查询没有成功?它是否可以是一个同时运行的SNMP管理器,将值重置回来?只是一个疯狂的想法。。。你知道吗

顺便说一句,mpModel=1表示SNMP版本2c。以防您的SNMP代理更喜欢任何其他SNMP版本。你知道吗

相关问题 更多 >