在timeou之前未收到SNMP响应

2024-05-23 15:49:41 发布

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

我是Pysnmp的大人物。我刚装上它开始学习。 当我收到任何一个同步的SNMP命令时,我没有收到任何一个命令的帮助!! 我的代码是

from pysnmp.entity.rfc3413.oneliner import cmdgen

cmdGen = cmdgen.CommandGenerator()

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
    cmdgen.CommunityData('public'),
    cmdgen.UdpTransportTarget(('localhost', 161)),
    '1.3.6.1.2.1.1.1.0',
    '1.3.6.1.2.1.1.6.0'
)

# Check for errors and print out results
if errorIndication:
    print(errorIndication)
else:
    if errorStatus:
        print('%s at %s' % (
            errorStatus.prettyPrint(),
            errorIndex and varBinds[int(errorIndex)-1] or '?'
            )
        )
    else:
        for name, val in varBinds:
            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))

Tags: andname命令forifvalelseprint
2条回答

您的代码没有任何问题,但可能有两个可能的原因导致您得到响应。在

  1. 您的“localhost”中没有配置snmp。尝试连接到已配置snmp的设备ip。

  2. 您的communityData字符串在设备(本地主机)上不是“public”。

检查一下这两件事,看看进展如何。如果您没有设备可以工作,那么尝试GNS3将是最好的选择。在

通过安装SNMP(在Linux操作系统上)并更改其配置文件来更正此问题。在

  1. apt-get-update和apt-get-install-snmpd
  2. 添加“udp:161 udp6:161英寸/var/lib/snmp/snmpd.conf公司在

相关问题 更多 >