Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andywis opened this issue Sep 7, 2020 · 1 comment
Open

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

andywis opened this issue Sep 7, 2020 · 1 comment

Comments

@andywis
Copy link

andywis commented Sep 7, 2020

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'])
@andywis
Copy link
Author

andywis commented Sep 7, 2020

it might be necessary to return data rather than sending it to stdout/stderr as well, but I hope you get the idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant