pythonnetwork-programmingsnmppysnmp

PySNMP Fetch variable timeout


I am working on an SNMP simulator in python and I am trying to follow some of the examples. I am having trouble running one of the example scripts that performs SNMP GET operation for a sysDescr.0 object at a publicly available SNMP Command Responder.

I have downloaded all the required packages via pip.

This is the following code (sorry if the formatting is wrong, fairly new here):

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
       CommunityData('public', mpModel=0),
       UdpTransportTarget(('demo.xxxx.com', 161)),
       ContextData(),
       ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
)

if errorIndication:
    print(errorIndication)
elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
                        errorIndex and varBinds[int(errorIndex) -1][0] or '?'))
else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

You can download the source code from their website, this file is called v1-get1.py. I am running this script on my Macbook Pro (Sierra) terminal using the command:

$python v1-get1.py

I am using python version 2.7.10 and have tried running this on python version 3.6.3 and i get the following error:

No SNMP response received before timeout

I have tried replacing the public server with other public servers I find online but I keep getting the same timeout response. Is there something that I am missing here? Or can someone who is familiar with pysnmp explain some of the fundamentals that I may be missing?


Solution

  • Your script works for me. I suspect you may have a local firewall that drops either request or response SNMP packets (UDP/161). Try running your script at some different network.

    BTW, there is the SNMP simulator tool available as well, https://docs.lextudio.com/snmp/snmp-simulation-service#.