Skip to content

How to get the following items in next_cmd? #475

@kovenko

Description

@kovenko
# pip install pysnmp pysnmp-mibs

import asyncio
from pysnmp.hlapi.v3arch.asyncio import *

async def walk(host, port, community):
    return next_cmd(
        SnmpEngine(),
        CommunityData(community, mpModel=1),
        await UdpTransportTarget.create((host, port)),
        ContextData(),
        ObjectType(ObjectIdentity('IF-MIB', 'ifIndex')),
        ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
        ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
        ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed'))
    )

async def main():
    errorIndication, errorStatus, errorIndex, varBind = await walk('asr.loc', 161, 'PUB')
    print(''.join([x.prettyPrint()+'\n' for x in varBind]))

    errorIndication, errorStatus, errorIndex, varBind = await walk('asr.loc', 161, 'PUB')
    print(''.join([x.prettyPrint()+'\n' for x in varBind]))

    errorIndication, errorStatus, errorIndex, varBind = await walk('asr.loc', 161, 'PUB')
    print(''.join([x.prettyPrint()+'\n' for x in varBind]))

if __name__ == '__main__':
    asyncio.run(main())
    pass

Result loop

IF-MIB::ifIndex.1 = 1
IF-MIB::ifDescr.1 = GigabitEthernet0/0/0
IF-MIB::ifType.1 = ethernetCsmacd
IF-MIB::ifSpeed.1 = 1000000000

IF-MIB::ifIndex.1 = 1
IF-MIB::ifDescr.1 = GigabitEthernet0/0/0
IF-MIB::ifType.1 = ethernetCsmacd
IF-MIB::ifSpeed.1 = 1000000000

IF-MIB::ifIndex.1 = 1
IF-MIB::ifDescr.1 = GigabitEthernet0/0/0
IF-MIB::ifType.1 = ethernetCsmacd
IF-MIB::ifSpeed.1 = 1000000000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions