Python 如何通过身份验证在Cisco路由器中获取SNMP OID值
我在下面编写一个示例代码,用于通过SNMP获取python pysnmp模块的Cisco交换机信息 执行以下代码后,我收到“超时前未收到SNMP响应”Python 如何通过身份验证在Cisco路由器中获取SNMP OID值,python,networking,snmp,pysnmp,Python,Networking,Snmp,Pysnmp,我在下面编写一个示例代码,用于通过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 ag
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相关的信息。诊断此问题的最快方法是使用您知道有效的现有实用程序,并使用您认为有效的身份验证对该IP地址进行验证。 如果该实用程序(例如NET-SNMP snmpwalk或snmpgetnext)不起作用,则问题可能不在代码中,而在于您对如何访问SNMP代理的理解。你确定社区字符串“公共”是有效的吗 从成功开始工作总比从失败中吸取教训好