- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 snmpwalk 在某些界面上获取一些信息和统计数据。我用这个:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in snmp_res:
print "snmp_res:: ", x
我得到的答案是:
snmp_res:: lo
snmp_res:: EtherNet Adapter XYZ
答案正确,但我需要更多信息。当我用 snmpwalk 从 linux 命令做同样的事情时,我得到了更多信息,例如:
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: EtherNet Adapter XYZ
“EtherNet Adapter XYZ”的 ID 为 2,我也需要该值来引用界面上的其他统计信息。我如何使用 python 和 snmp 获取它们?
最佳答案
直接来自 the documentation :
snmpwalk(<Varbind/VarList>, <Session args>))
Takes args of netsnmp.Session preceded by a Varbind or VarList from which the 'walk' operation will start. Returns a tuple of values retrieved from the MIB below the Varbind passed in. If a VarList is passed in it will be updated to contain a complete set of VarBinds created for the results of the walk. It is not recommended to pass in just a Varbind since you loose the ability to examine the returned OIDs. But, if only a Varbind is passed in it will be returned unaltered.
Note that only one varbind should be contained in the VarList passed in. The code is structured to maybe handle this is the the future, but right now walking multiple trees at once is not yet supported and will produce insufficient results.
您已经传递了一个VarList,所以您已经拥有了您需要的东西。您只需要正确检查结果即可。
The tests举个例子:
vars = netsnmp.VarList(netsnmp.Varbind('system'))
vals = sess.walk(vars)
print "v1 sess.walk result: ", vals, "\n"
for var in vars:
print " ",var.tag, var.iid, "=", var.val, '(',var.type,')'
关键是修改了input 变量以提供您需要的内容。返回值对你来说没有多大值(value)(笑)。
将所有这些放在一起看起来您想要以下内容:
import netsnmp
serv = "172.16.1.1"
snmp_pass = "private"
oid = netsnmp.VarList('IF-MIB::ifName','IF-MIB::ifDescr')
snmp_res = netsnmp.snmpwalk(oid, Version=2, DestHost=serv, Community=snmp_pass)
for x in oid:
print "snmp_res:: ", x.iid, " = ", x.val
(免责声明:无法测试;根据需要进行调整)
该文档中有足够的关于 VarBind 和 VarList 的信息,可以找出最好的东西来摆脱 x
.
x.iid
但是,是实例标识符,所以它应该给你 1
和 2
你要找的不要忘记检查 x.tag
不过,也可以是 IF-MIB::ifName
或 IF-MIB::ifDescr
(或类似的东西;您必须进行试验)。
关于Python Netsnmp 和 snmpwalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53614670/
我正在尝试通过 SNMP 从服务器收集数据。snmpwalk 不会像 Web 界面那样返回任何基本数据,但我需要通过 SNMP 获取此类数据。 snmpwalk -c public -v 1 . i
我正在尝试从设备中获取值。当我通过腻子运行 snmp 时,它运行良好并给出了结果。命令是这样的。 snmpwalk -v 2c -c public 1.2.3.4 1.5.2.33.1.4.2.2.1
我有一个在 linux 上的 tomcat(少数 java servlet)中运行的应用程序。现在我的任务是监视这个 tomcat(而不是单个 servlet)中的资源(例如 CPU、内存使用情况等)
我们试图在 Ubuntu 服务器上制作一个脚本,该脚本从 snmpwalk 命令读取结果的数量,然后将其发送到 Cacti 以进行绘图。 由于我们都没有任何类型的编程知识,而且根据我们的尝试,我们还没
如何使用 snmp4j 和社区字符串索引进行 snmpwalk? 我可以通过像 public@123 这样更改社区字符串来进行社区字符串索引(123是vlanId) 但这只适用于 snmpget !!
我正在尝试使用 snmpwalk 在某些界面上获取一些信息和统计数据。我用这个: import netsnmp serv = "172.16.1.1" snmp_pass = "private" oi
在 linux 上我可以执行这样的事情 snmpwalk -c public -v2c -m 我想使用 snmp4j 在 java 中实现同一行。是否可以?我没有找到任何使用 -m 参数加载供应商
我尝试构建一个 python 脚本来从 snmp 传感器获取温度。 如果我在 Linux 终端上使用此命令行 snmpwalk 10.100.2.21 -On -v 1 -c public .1.3.
我在我的代码中使用 net-snmp。对于 snmpget,我使用此代码,它是 100% 正确的。 string oiids = ".1.3.6.1.4.1.30429.1.3.2.1.0" ;
我正在使用 this example 发送对 snmp 节点 的请求: PDU pdu = new PDU(); pdu.add(new VariableBinding(new OID("1.3.6.
我尝试执行: snmpwalk -v 3 -u snmpv3username -A -a MD5 -l authNoPriv localhost .1.3.6.1.4.1.334.72.1.1.6.
我在 opensuse linux 上运行 nagios 服务器,通过 snmp 链接到 esx 3.5 服务器 我试图让 snmpwalk 返回一个数组,但它只返回一个值。 在 esx box 上,
我想构建一个java工具来提取一些设备(交换机、路由器等)的lldp信息来制作“拓扑图”。 尝试 snmpwalk,我只发现无用的信息(对于本例)。我认为 lldp mib 是 1.0.8802.1.
我有一个 MIB,其中 3 个表包含标记为“accessible-for-notify”的第一个元素项目,例如: -- 1.3.6.1.4.1.3979.7.4.3.2.2.1 awO
我想重现以下 SNMP 命令的行为: snmpwalk -v2c -cpublic 192.168.0.10 1.3.6.1.2.1.25.2.3.1.3 这给了我这个输出: iso.3.6.1.2.
我是 Linux 网络新手。我正在尝试在 Linux 电脑 交换机 NAS(Buffalo TS500D) 之间配置 SNMP。我已在 Linux 电脑中配置了 snmpd 并在 NAS 中启用了
我制作了一个自定义 sub 以使用 Open3 在 perl 中运行各种终端命令。 我在使用 snmpwalk 时遇到了一个奇怪的问题,当我在终端中运行该命令时它可以工作,但在 Open3 中它不会。
我想使用 snmpwalk 分别获取 cpu1 和 cpu2 的使用情况。 我的是双核cpu。谁能知道 cpu1 和 cpu2 使用的确切 OID 是什么? 我使用的是centos操作系统。谢谢 最佳
我是 Linux 新手。我正在使用 MIB for Dummies ( http://www.net-snmp.org/wiki/index.php/MIB_for_Dummies ) 配置文件 (m
我是一名优秀的程序员,十分优秀!