Skip to content

Ability to use snmpwalk.py from other python programs #16

@andywis

Description

@andywis

I'd like to suggest a change to snmpwalk.py to allow it to be used from other programs.

I propose putting everything from snmpEngine = engine.SnmpEngine() to the end of the program in a function called "run()".

e.g.

def run(arg_vector):
    snmpEngine = engine.SnmpEngine()

    ctx = {}

    try:
        # Parse c/l into AST
        ast = Parser().parse(
            Scanner().tokenize(' '.join(arg_vector))
        )

    main.generator((snmpEngine, ctx), ast)
    # etc....

then, at the end,

if __name__ == '__main__':
    run(sys.argv[1:])

this allows me to from snmpwalk.py import run in my own code, and use it,
I don't have to make my python code run a subshell to run your python code :-)
e.g.

from snmpwalk import run

run('-v3', '-l', 'authPriv', '-u', 'myuser',
         '-a', 'SHA', '-A', 'apasswd12345', '-x', 'AES', '-X', 'prvpass12345',
         '127.0.0.1', '.1.3.6.1.2.1.2.2.1.2'])

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