[英]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.