简体   繁体   English

python下的SNMP OID,试图将MAC连接到交换机

[英]SNMP OIDs under python, trying to get MACs connected to a switch

I'm trying to create a script in python using snmpwalk to get the current devices connected to my switches and which port are they using (I get the MAC address and then, with a database I have, I make the translation to IP or hostname). 我正在尝试使用snmpwalk在python中创建脚本以获取连接到我的交换机的当前设备以及它们使用的端口(我获取了MAC地址,然后使用我拥有的数据库将其翻译为IP或主机名)。

Well, everything is going fine but I realize that the OID number of this information change between some switches. 很好,一切都很好,但我意识到此信息的OID编号在某些开关之间会发生变化。

I'm trying to get this OID: 1.3.6.1.2.1.17.4.3.1.2 我正在尝试获取此OID:1.3.6.1.2.1.17.4.3.1.2

This works fine and I get the MACs and the port number. 这工作正常,我得到了MAC和端口号。

But in some of my switches is this one: 1.3.6.1.2.1.17.7.1.2.2 And in other ones is: 1.3.6.1.2.1.17.4.3.1.2 但是在我的某些交换机中是这样的:1.3.6.1.2.1.17.7.1.2.2在其他交换机中是:1.3.6.1.2.1.17.4.3.1.2

I'm quite confuse about that and I'm wondering if I'm doing well looking for the OID number instead the name. 我对此感到非常困惑,我想知道我是否在寻找OID号而不是名称方面做得很好。 Anyway, I tried to find the information using some names (sysUpTime etc) but snmpwalk does not work with names (at least, It does not work for me and I'm not sure which name I have to use to get this information). 无论如何,我试图使用某些名称(例如sysUpTime等)来查找信息,但是snmpwalk不适用于名称(至少,它对我不起作用,并且我不确定我必须使用哪个名称来获取此信息)。 For example, I tried: 例如,我尝试过:

$ snmpwalk -v 1 -c public sea-kmSwitch dot1dTpFdbPort
dot1dTpFdbPort: Unknown Object Identifier (Sub-id not found: (top) -> dot1dTpFdbPort)

I know there are snmp modules in python, but I did not find good documentation and examples (pysnmp, pynetsnmp) so I tried to do the script using the linux commands. 我知道python中有snmp模块,但是我没有找到好的文档和示例(pysnmp,pynetsnmp),因此我尝试使用linux命令来编写脚本。

So, the question is: how can I know which OID number I have to get? 因此,问题是:我怎么知道我必须获得哪个OID号? could I use any OID name? 我可以使用任何OID名称吗? and how? 如何?

Thanks and sorry about my english. 谢谢,对不起我的英语。

Your program does not work with SNMP names because you did not export a path where MIB files are placed and the list of MIB files you want to use. 您的程序无法使用SNMP名称,因为您没有导出放置MIB文件的路径以及要使用的MIB文件列表。

If you want to use Linux with NET-SNMP framework (ie snmpwalk command) then please set following environmental variables: MIBDIR and MIBS before you execute a script. 如果要使用带有NET-SNMP框架的Linux(即snmpwalk命令),请在执行脚本之前设置以下环境变量:MIBDIR和MIBS。

export MIBDIR=<path_to_mib_files>
export MIBS=ENTITY-MIB:SNMPv2-TC:<any_other_mibs_you_need>

You may export those variables directly in the script while running, just before calling any command using OID in form of SNMP name (ie sysLocation.0 instead of 1.3.6.1.2.1.1.6.0). 您可以在运行时直接在脚本中导出这些变量,就在使用OID以SNMP名称形式(即sysLocation.0而不是1.3.6.1.2.1.1.6.0)调用任何命令之前。

Please note that you have to define wider set of MIB files for MIB variable than required - this is because your specific MIB file most probably uses some RFC-based MIB files. 请注意,您必须为MIB变量定义比要求更广泛的MIB文件集-这是因为您的特定MIB文件很可能使用某些基于RFC的MIB文件。 To be sure what MIB files you need to export, take a look into IMPORTS section inside the MIB you are interested in. 为了确定需要导出哪些MIB文件,请查看您感兴趣的MIB内的IMPORTS部分。

Hope that helps. 希望能有所帮助。

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

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