How to get data from SNMP with python?

In the pysnmp example you are doing an SNMPGET (snmpget), not a GETNEXT (snmpwalk). If you change,

real_fun = getattr(generator, 'getCmd')

to

real_fun = getattr(generator, 'nextCmd')

you will start to see useful results.

As for the discrepancy you saw in the results between snmpwalk and the python net-snmp bindings result: snmpwalk and snmpbulkget behave differently. If you do an snmpbulkget from the command line with the same options as the snmpwalk you’ll receive the same results as your python net-snmp example.

If you update the following line in your python net-snmp example,

res = netsnmp.snmpgetbulk(oid, Version=2, DestHost='192.168.0.100', 
                          Community='pub')

to

res = netsnmp.snmpwalk(oid, Version=2, DestHost='192.168.0.100', 
                       Community='pub')

then you should now get the same list of results from the python net-snmp example as you see when you do an snmpwalk on the command line.

Leave a Comment

error code: 523