读取IPAddress类型的SNMP对象索引 [英] Reading SNMP Object index of type IPAddress
问题描述
在像mib-2.interfaces.ifTable
这样的简单SNMP表中,ifIndex
是该表的索引,因此您读取ifIndex
.1(即从ifIndex
的直接子节点读取值)以获取该表的索引.表格的第一行.很简单.
In a simple SNMP table like mib-2.interfaces.ifTable
, ifIndex
is the index for the table, so you read ifIndex
.1 (i.e. read value from direct child nodes of ifIndex
) to get the index for the first row of the table. Simple enough.
但是对于mib-2.ip.ipRouteTable
之类的东西却不那么明显.在这种情况下,ipRouteIfIndex
是索引列.就像ifIndex
一样,它被定义为INTEGER.但是,您不能读取直接子节点(即ifIndex
.0是直接子节点),而需要读取ifIndex.0.0.0.0
才能获得该值.因此,当它不是索引列的直接子代时,如何知道如何找到该值?
But it's not as obvious with something like mib-2.ip.ipRouteTable
. In that case ipRouteIfIndex
is the index column. It's defined as INTEGER just like ifIndex
was. However, you can't read the direct child nodes (i.e. ifIndex
.0 is a direct child), but instead need to read ifIndex.0.0.0.0
to get to the value. So how does one know how to find the value when it's not a direct child of the index column?
有些我不理解的概念. (可能与SNMP对象以.分隔的事实有关,但IP地址也是如此,我不知道如何识别差异).
There is some concept that I'm not understanding. (Probably having to do with the fact that SNMP objects are delimited by . but so are IP addresses, and I can't tell how to recognize the difference).
推荐答案
在这种情况下,您有一个包含多个索引的表.
Note that you have a table with multiple indices in this particular case.
事实是您不能使用snmp-get
服务直接读取表条目,因为索引是动态的(因此是OID地址).但是您可以使用snmp-get-next
(v1)和snmp-get-bulk
(v2)服务发现这些值.
The fact is that you cannot directly read the table entries with snmp-get
service, since the index is dynamic (and, as a consequence, the OID address). But you can discover the values with snmp-get-next
(v1) and snmp-get-bulk
(v2) services.
例如,您可以读取索引(并存储它们以供以后查询表项)或直接读取表中的项:
For example, you can read the indices (and store them for querying table items later) or directly read the items of the table :
- 您向
snmp-get-next
询问 IP-MIB :: ipAdEntNetMask - 回复将为 IP-MIB :: ipAdEntNetMask.172.16.38.42 IPV4 255.255.0.0
- (因此:在这种情况下,第一个索引是172.16.38.42!)
- 您迭代并在 IP-MIB :: ipAdEntNetMask.172.16.38.42 之后询问下一个值
- 回复将为 IP-MIB :: ipAdEntNetMask.172.16.11.43 IPV4 255.255.0.0
- 等.直到没有其他值,或者该值不在同一棵树上
- you ask
snmp-get-next
for IP-MIB::ipAdEntNetMask - the reply will be IP-MIB::ipAdEntNetMask.172.16.38.42 IPV4 255.255.0.0
- (So: first index is 172.16.38.42 in that case!)
- you iterate and ask next value after IP-MIB::ipAdEntNetMask.172.16.38.42
- the reply will be IP-MIB::ipAdEntNetMask.172.16.11.43 IPV4 255.255.0.0
- etc.. until there is no other value, or the value is not on the same tree
服务snmp-get-bulk
将使您可以通过这种方式直接查询N个值.
The service snmp-get-bulk
will enable you to query N values directly in this way.
看看在表方面做得很好的 Net-Snmp's snmptable
:
Have a look at Net-Snmp's snmptable
that does good job with tables : http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmptable
这篇关于读取IPAddress类型的SNMP对象索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!