我是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()))
您的代码没有任何问题,但可能有两个可能的原因导致您得到响应。在
您的“localhost”中没有配置snmp。尝试连接到已配置snmp的设备ip。
您的communityData字符串在设备(本地主机)上不是“public”。
检查一下这两件事,看看进展如何。如果您没有设备可以工作,那么尝试GNS3将是最好的选择。在
通过安装SNMP(在Linux操作系统上)并更改其配置文件来更正此问题。在
相关问题 更多 >
编程相关推荐