简体   繁体   English

如何在Python中获取SNMP表

[英]How to get SNMP table in Python

How is it possible to implement getting of SNMP table in Python + NetSnmp? 如何在Python + NetSnmp中实现SNMP表的获取?

Simple set and get for Python + NetSNMP work fine: Python + NetSNMP的简单设置和获取工作正常:

myArgs = ['enterprises', 'set', '27142.1.1.20.1.2.1.1.1', '1', 'INTEGER']
var = netsnmp.Varbind(*myArgs)
res = netsnmp.snmpset(var, Version = 2, DestHost = 192.168.1.2, Community='private')

I would like to know how to implement the following NetSNMP command in Python: 我想知道如何在Python中实现以下NetSNMP命令:

snmptable -v 2c -c public -Ob 172.16.67.240 .1.3.6.1.2.1.2.2

Thanks 谢谢

Tried to solve it unsuccessfully with getBulk in Python. 尝试使用Python中的getBulk解决不成功的问题。 It works quite strange returning only part of the table irrespective of getBulk parameters. 无论getBulk参数如何,仅返回表的一部分都非常奇怪。 Solved it by directly invoking Linux shell from Python. 通过直接从Python调用Linux Shell解决了该问题。 Got the correct table in out variable: 得到了在正确的表out变量:

import subprocess
p = subprocess.Popen(['snmptable', '-v', '2c', '-c', 'public', '-Ob', '172.16.67.240',    '.1.3.6.1.2.1.2.2'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

I would appreciate any better ideas! 我将不胜感激!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM