pysnmp icon indicating copy to clipboard operation
pysnmp copied to clipboard

nextCmd is returning values outside of the table I want to walk

Open 0byt3 opened this issue 4 years ago • 2 comments

I want to walk the dot1qVlanStaticName column of the dot1qVlanForbiddenEgressPorts table which is '1.3.6.1.2.1.17.7.1.4.3.1.3.1.1';

If I use snmpwalk I get the values from that column in that table as per expected, however pysnmp returns a lot of OIDs that are not from that table. Code: `from pysnmp.hlapi import nextCmd,SnmpEngine,CommunityData,UdpTransportTarget,ContextData,ObjectType,ObjectIdentity

for (errorIndication,errorStatus,errorIndex,varBinds) in nextCmd(SnmpEngine(),CommunityData('read'),UdpTransportTarget(('10.1.3.239',161)),ContextData(),ObjectType(ObjectIdentity('1.3.6.1.2.1.17.7.1.4.3.1.1')),lookupMib=False): if errorIndication: print(errorIndication) break elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0])) break else: for varBind in varBinds: print(' = '.join([x.prettyPrint() for x in varBind]))`

0byt3 avatar Mar 10 '20 22:03 0byt3

I was facing this issue when given a whole MIB, I was seeing other MIBS values as well, but passing lexicographicMode=False solved the issue for me. Now only see values from my MIB.

tkc17 avatar Apr 06 '20 11:04 tkc17

@0byt3 "pysnmp returns a lot of OIDs that are not from that table" is exactly how SNMP GET NEXT (and nextCmd) should work, and it queries the next available object endlessly till all the objects are processed.

SNMP WALK, as a sequence of GET NEXT requests, can work the same way, but the command line utility from PySNMP decides to stop when the next returned object goes out of the table, https://github.com/etingof/snmpclitools/blob/master/scripts/snmpwalk.py#L144 That might have given you a wrong impression, but you really need to know the internals and then figure out that you misunderstood.

lextm avatar Jan 20 '23 05:01 lextm