[英]How to get SNMP OID Values in Cisco Router with Authentication
我正在编写下面的示例代码,用于通过 SNMP 为 python pysnmp 模块获取 Cisco 交换机信息。
执行以下代码后,我收到“超时前未收到 SNMP 响应”。
from pysnmp.entity.rfc3413.oneliner import cmdgen
import time
#SNMP agent address
SNMP_AGENT_HOST = 'IPADDRESS' # IP adderess
#SNMP default port
SNMP_PORT = 161
#Add SNMP agent community here
SNMP_COMMUNITY = 'public'
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData(SNMP_COMMUNITY),
cmdgen.UdpTransportTarget((SNMP_AGENT_HOST, SNMP_PORT)),
'1.3.6.1.4.1.9.2.1.56.0', # Cisco Switch OID
'1.3.6.1.4.1.9.2.1.57.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()))
我得到了结果
No SNMP response received before timeout
我想通过 GET 调用获取所有 OID 相关信息。
诊断此问题的最快方法是使用您知道有效的 EXISTING 实用程序,并使用您认为应该有效的身份验证对该 IPADDRESS 进行尝试。 如果该实用程序,例如。 NET-SNMP snmpwalk 或 snmpgetnext 不起作用,那么您的问题很可能不在您的代码中,而是您对如何访问 SNMP 代理的理解。 例如。 您确定社区字符串“public”有效吗?
从成功开始工作总是比从失败中插入要好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.