当我只知道远程系统的 IP 地址时,如何获取远程系统的 MAC 地址?

发布于 2024-07-21 13:17:53 字数 625 浏览 7 评论 0 原文

我正在开发 LAN 唤醒服务,该服务将从网站运行,并且应该与许多不同的平台交互 - 因此,没有仅限 Windows 的解决方案。 当用户在网站上注册其系统时,我需要获取用于构建 “魔法”数据包。 我有一个 Java Applet 能够为我执行此操作,并且知道可以使用 ActiveX 控件,但我想知道是否有一种方法可以通过查询路由器/交换机来在服务器端执行此操作。 由于系统可能位于多个不同物理子网中的任何一个上,因此使用 ARP 不起作用——除非有办法配置路由器来代表我执行 ARP。

有人知道任何网络 API(专有的或其他的)可用于在给定 IP 地址的情况下查找 MAC 地址吗? 我认为我们正在使用思科路由器,但这是一个复杂的网络,并且可能涉及多个级别的多个供应商。 在向网络之神献祭之前,我想了解一些可能的解决方案的背景信息。 如果技术上不可能,那就没有必要自卑。 :-)

编辑: 我们确实设置了允许定向广播的网络基础设施,但由于网络掩码并不总是 /24,因此找出确切的广播地址是我需要解决的另一个难题。

I'm working on a Wake on LAN service that will run from a web site and should interact with many different platforms - therefore, no Windows-only solutions. When a user registers their system with the web site, I need to get the MAC address to use in constructing the "magic" packet. I have a Java Applet that is able to do this for me and am aware of an ActiveX control that will work, but I'm wondering if there is a way to do this server-side by querying routers/switches. Since the system may be on any of a number of different physical subnets, using ARP won't work -- unless there's a way to configure the router(s) to perform the ARP on my behalf.

Anyone know of any network APIs, proprietary or otherwise, that can be used to look up MAC addresses given an IP address? I think we're using Cisco routers, but it's a complicated network and there may be multiple vendors involved at various levels. I'd like to get some background information on possible solutions before I go to make a sacrifice to the network gods. No point in abasing myself if it's not technically possible. :-)

EDIT: We do have the network infrastructure set up to allow directed broadcast, though figuring out the exact broadcast address since netmasks are not always /24 is another conundrum that I need to solve.

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

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

发布评论

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

评论(11

壹場煙雨 2024-07-28 13:17:53

如果您位于使用 DHCP 的本地网络上,您也许可以在服务器数据库中查找以获取使用该地址的最后一个用户的 MAC。 将来,您可以监视网络中的 ARP 请求并将响应缓存在某种表中。 您还可以考虑使用 RMON 或 SNMP 来尝试查询交换机和路由器上的地址表。

应该注意的是,要跨路由器使用 WoL,您需要启用定向广播,或者需要在本地网段中拥有中继服务器。

自从我玩路由器和交换机以来已经有一段时间了,但这可能是使用 SNMP 查询内容的起点 http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a00801c9199.shtml

If you are on a local network that uses DHCP you might be able to look in the servers database to get the MAC of the last user with that address. In the future you could watch the network for ARP requests and cache the responses in some sort of table. You might also look at using RMON or SNMP to try and query the Address Tables on the switches and routers.

It should be noted that to use WoL across routers you either need to enable Directed Broadcasts or you need to have a relay server in the local segment.

Been a while since I played routers and swtiches but this might be a starting point for what to query using SNMP http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a00801c9199.shtml

夏末染殇 2024-07-28 13:17:53

使用以下命令:

getmac /s destIp 

获取远程会话 Mac 地址。

Use the following:

getmac /s destIp 

To get the remote session Mac address.

最好是你 2024-07-28 13:17:53

你已经说了我能想到的一切...

源 MAC 地址随着数据包从一个设备跳到另一个设备而变化,因此除非客户端位于同一子网上,否则服务器将无法获取 MAC 地址。 (您可以通过 ARP 来完成)

签名的 java applet 或 activex 控件将是最简单的解决方案。 它将能够(几乎被动地)获取您需要的所有网络信息(IE 甚至不会提示运行签名的小程序)

如果您完全了解正在使用该服务的网络,那么您可能可以查询网关的客户端-通过 SNMP 或 CDP 列出。 您将能够将 IP 地址映射到 MAC 地址...但这实际上取决于供应商(但很常见),并且不会比拥有一个小程序好多少(我认为)。

You've said everything I can think of...

The source MAC address changes as a packet hops from device to device so unless the client is on the same subnet, the server won't be able to get the MAC address. (You would do it via ARP)

A signed java applet or activex control would be the easiest solution. It would be able to (almost passively) get all the networking info you need (IE doesn't even prompt to run a signed applet)

If you are fully aware of the network that is using the service then you could probably query a gateway's client-list via SNMP or CDP. You would be able to map out IP-Addresses to MAC addresses... but this is really vendor dependent (but common) and wouldn't be much better (imo) than having an applet.

牛↙奶布丁 2024-07-28 13:17:53

目前,该应用程序使用 Java 6 小程序,它允许我从远程系统中提取主机名和 MAC 地址。 我不喜欢对 Java 6 的这种依赖,但 Snow Leopard 和 Windows 都支持它,所以我可能可以忍受它。

在相关方面,我们的网络人员向我寻求帮助,将一些现有代码转换为 ASP.NET。 在谈话过程中,我询问他们是否有实时的 MAC 地址信息(因为他们会根据可疑的网络活动(病毒/蠕虫)关闭端口)。 事实证明他们确实如此,我们也许能够利用这个项目来访问网络数据库中的信息。

Currently the application is using a Java 6 applet that allows me to extract both the hostname and the MAC address from the remote system. I don't like having this dependency on Java 6, but Snow Leopard and Windows both support it, so I can probably live with it.

On a related-front our networking folks approached me for some help with converting some existing code to ASP.NET. During the conversation I asked if they had live MAC address information (since they do port shutoffs based on suspicious network activity -- viruses/worms). Turns out they do and we may be able to leverage this project to get access to the information from the network database.

前事休说 2024-07-28 13:17:53

我认为没有任何方法可以实现这一点。 当 IP 数据包通过第一个路由器时,主机的 MAC 信息会丢失(正如您所知,MAC 仅用于以太网层)。 如果距离您的 PC 最近的路由器能够将远程 MAC 代码告诉您,那么它只会看到您的 PC 和“另一端”之间的下一个路由器的 MAC。

I don't think there is any way to accomplish this. When the IP packet goes via the first router the host's MAC information is lost (as you know MAC is only used in ethernet layer). If the router most close to your PC was capable of telling the remote MAC code to you, again it would only see the MAC of the next router between your PC and the "other end".

禾厶谷欠 2024-07-28 13:17:53

开始牺牲。

就网络而言,没有通用的方法可以做到这一点,除非您不涉及路由器。 使用路由器时,您将永远不会看到原始系统的 MAC 地址。

这假设原始系统只有一个网络接口,因此只有一个 MAC 地址。

事实上,您是否确定您的“神奇数据包”(无论是什么)将通过路由器到达您希望其到达的系统? 这听起来像是路由器或其他网络基础设施应该执行的功能。

Start sacrificing.

There's no general way to do this in terms of the network unless you have no routers involved. With a router involved, you will never see the MAC address of the originating system.

This assumes that the originating system only ever has a single network interface, so has only a single MAC address.

In fact, are you even sure that your "magic packet" (whatever that is) will reach the system you want it to reach, through the routers? That sounds like a function the routers or other network infrastructure should be performing.

℡寂寞咖啡 2024-07-28 13:17:53

Mac地址仅在网段上使用,并且在每一跳都会丢失。 仅保留端到端的 IP - 即使这样,在 Natted 时,发件人 ip 地址也会被重写。 我想我的答案是,除非所有东西都在同一网段上,或者您的路由器设置为代理 arp(这不太现实),否则不可能。

Mac address is only used on network segments, and is lost at each hop. Only IP is preserved for end-to-end - and even then the from ip address is rewritten when Natted. I guess my answer is, not possible unless everything is on the same network segment, or your routers are set up for proxy arp (which is not really realistic).

独自唱情﹋歌 2024-07-28 13:17:53

您只能获取同一网络上计算机的 ARP 表中的 MAC 条目。 如果您通过路由器连接到计算机,那么您将只能在 ARP 表中看到路由器的 MAC 地址。 因此,除非它是同一网络上的主机(不涉及路由器),否则无法知道外部主机的 MAC 地址

顺便说一句,SO 上已经有很多类似的问题

You can only get MAC entries in the ARP table for machines on the same network. If you connect to a machine via a router then you will only see the routers MAC address in the ARP table. So there is no way of knowing the foreign host’s MAC address unless it's a host on the same network (no routers involved).

And by the way there are many similar question already on SO.

咋地 2024-07-28 13:17:53

如果是windows系统你可以使用NBTSTAT -A
这将返回 netbios 信息和 IP 是否有

任何管理系统(例如 SMS 或 Altiris)都会有此信息

DHCP 服务器是个好主意

如果它是本地的,您可以 ping 它,然后快速运行 ARP -a
寻找IP,MAC就会在那里。
您可能需要编写一个小批处理文件。

如果您有权访问 PC,则可以使用 WMI 通过 DHCP 访问网卡的信息。

if it's a windows system you can use NBTSTAT -A
this will return the netbios info and the IP is there

any Management system like SMS or Altiris will have this info

The DHCP server is a good idea

If it's local you can ping it and then quickly run ARP -a
look for the IP and the MAC will be there.
you might need to write a small batch file.

if you have access to the PC you can use WMI to access the info for the Nic with DHCP.

闻呓 2024-07-28 13:17:53

如上所述,如果该主机位于同一子网中,我们可以从已知的 IP 地址获取 MAC 地址。 首先ping该ip; 然后看看 arp -a | grep 并解析 nix* 上的字符串以获取 mac 地址。

我们可以从所有编程语言的标准 API 发出系统命令,并且可以解析输出以获取 mac 地址。Java api 可以 ping 一个 IP,但我不确定我们是否解析 ping 输出(某些库可以做到)。
最好避免发出系统命令并找到替代解决方案,因为它并不是真正独立于平台的方式。

礼貌:萨利姆·巴蒂教授

As said above we can get mac address from a known IP address if that host is in the same subnet. First ping that ip; then look at arp -a | grep and parse the string on nix* to get mac address.

We can issue system command from all programming languages standard API's and can parse the output to get mac address.Java api can ping an IP but I am not sure if we parse the ping output(some library can do it).
It would be better to avoid issuing system command and find an alternative solution as it is not really Platform Independent way of doing it.

Courtesy: Professor Saleem Bhatti

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