如何通过身份验证在Cisco路由器中获取SNMP OID值

2024-05-20 19:36:19 发布

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

我在下面编写一个示例代码,用于通过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相关信息


Tags: 代码import信息ciscoagentsnmpprintpysnmp
1条回答
网友
1楼 · 发布于 2024-05-20 19:36:19

诊断这种情况的最快方法是使用一个已知有效的现有实用程序,并使用您认为应该有效的身份验证对该IP地址进行验证。 如果该实用程序(例如NET-SNMP snmpwalk或snmpgetnext)不起作用,则问题可能不在代码中,而在于您对如何访问SNMP代理的理解。你确定社区字符串“公共”是有效的吗

从成功开始工作总比从失败中吸取教训好

相关问题 更多 >