It is impossible with the help of pysnmp to create an analogue of the command:

snmpwalk -v 2c -c XFiles 172.18.114.6 ifOperStatus 

I'm trying to get this code:

 errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), CommunityData(comm), UdpTransportTarget( (ip, 161), timeout=2.0, retries=0 ), ContextData(), ObjectType(ObjectIdentity('IF-MIB','ifOperStatus'))) ) 

Mistake:

 pysnmp.smi.error.MibNotFoundError: IF-MIB compilation error(s): missing 

But obviously dig the wrong way. Probably need to use not getCmd ?

    1 answer 1

    In this case, you need to use bulkCmd, for example:

     def GetArrayPortStatus(ip,comm,oid): rez=None for errorIndication, errorStatus, \ errorIndex, varBinds in bulkCmd( SnmpEngine(), CommunityData(comm), UdpTransportTarget((ip, 161)), ContextData(), 0, 50, # GETBULK specific: request up to 50 OIDs in a single response ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.8')), lookupMib=False, lexicographicMode=False): if errorIndication: print(errorIndication) break elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1][0] or '?')) break else: for varBind in varBinds: print(' = '.join([x.prettyPrint() for x in varBind])) return rez