简体   繁体   中英

How to get SNMP OID Values in Cisco Router with Authentication

Am writing a Sample code below for fetching Cisco Switch Information through SNMP for the python pysnmp module.

after executing below code am getting 'No SNMP response received before timeout'.

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()))

I getting the result

No SNMP response received before timeout

I want to be fetch all OID related Information through the GET call.

Your quickest way of diagnosing this is to use an EXISTING utility that you know works, and try it against that IPADDRESS with the authentication that you think should work. If that utility, eg. NET-SNMP snmpwalk or snmpgetnext, does not work, then your problem is likely not in your code, but your understanding of how to access the SNMP agent. Eg. are you certain the community string "public" works?

It is ALWAYS better to work from success, than to interpolate from failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM