SNMP:如何在网络中查找 MAC 地址?

发布于 2024-11-03 00:07:13 字数 286 浏览 0 评论 0原文

我编写了一个 Perl 脚本来查询网络上的设备(交换机),它用于通过 LAN 查找 MAC 地址。但是,我想改进它,我的意思是,我必须向我的脚本提供这些参数:

  1. @mac 搜索
  2. 交换机的 IP
  3. 社区

我怎样才能只提供 IP 和社区?
我知道这取决于我的网络拓扑? 有一个主堆栈 3 台交换机(cisco 3750),然后将其链接到其他交换机(2960),级联。
有人有主意吗?

编辑:我不想指定开关。 只需提供@mac 和社区即可。

I've wrote a Perl script to query devices (switches) on the network, it's used to find an mac address over the LAN. But, I would like to improve it, I mean, I have to give to my script these parameters:

  1. The @mac searched
  2. Switch' IP
  3. Community

How can I do to just give IP and community ?
I know that it depends on my network topology ?
There is a main stack 3-switches (cisco 3750), and after it's linked to other ones (2960), in cascade.
Anyone has an idea ?

Edit : I would like to not specify the switch.
Just give the @mac and the community.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丑丑阿 2024-11-10 00:07:13

您必须解决两个问题...脚本将在哪里发送第一个查询...然后,假设您发现通过该交换机上的端口 1/2/1 获悉了 MAC 地址,并且该端口连接到另一台交换机。无论如何,您的脚本必须足够智能才能查询连接到端口 1/2/1 的交换机。继续相同的算法,直到没有开关可以查询。

您所要求的是可能的,但它需要您提前向脚本提供网络拓扑信息,或者使用 CDP 或 LLDP 动态发现它。 CDP 始终携带邻居的 IP 地址...有时您可以从 LLDP 获取该地址。 CDP 和 LLDP 都有可以查询的 MIB 对象。

You have to solve two problems... Where will the script send the first query... Then, suppose you discover that a mac address was learned through port 1/2/1 on that switch and that port is connected to another switch. Somehow your script must be smart enough to query the switch attached to port 1/2/1. Continue the same algorithm until you do not have a switch to query.

What you are asking for is possible, but it would require you to either give the script network topology information in advance, or to discover it dynamically with CDP or LLDP. CDP always carries the neighbor's ip address... Sometimes you can get that from LLDP. Both CDP and LLDP have MIB objects you can query.

寒尘 2024-11-10 00:07:13

基本上你需要两个脚本。您已经有一个用于收集数据的脚本,但查找单个 MAC 需要很长时间。想必您有每个交换机及其 IP 地址的完整列表。循环遍历它们,构建 CAM 表的数据库。然后当您需要搜索 MAC 时,只需查询您预先构建的数据库即可。大约每小时更新一次,您应该保持相当准确的结果。您可以通过并行运行多个 snmp 遍历来加速多个设备的查询。

You'll need two scripts basically. You already have a script to gather your data, but it takes too long to find a single MAC. Presumably you have a complete list of every switch and it's IP address. Loop over them all building a database of the CAM table. Then when you need to search for a MAC, just query your pre-built database. Update it about once an hour or so and you should maintain pretty accurate results. You can speed the querying of several devices by running multiple snmp walks in parallel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文