从 IPv4 中的(非本地)IP 地址获取 MAC 地址的最简单方法
有没有一种简单的方法可以获取通过 TCP/IPv4 套接字连接到我的应用程序的计算机的 MAC 地址?
或更笼统地说:
如果我有 IP 地址,获取 IPv4 中相应 MAC 地址的最佳方法是什么?
Is there an easy way to get a MAC address of a machine connected to my app via a TCP/IPv4 socket?
Or in more general terms:
If I have the IP address, what is the best way to get the corresponding MAC address in IPv4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MAC 地址仅用于下一跳。这基本上意味着客户端的原始 MAC 地址在第一跳之后将不可见。一般来说,如果您与客户端不在同一物理网段,则无法获取 IP 并获取 MAC(反之亦然)。
MAC addresses are used only for the next hop. This basically means the client's original MAC address won't be visible after it's first hop. In the general sense, if you are not on the same physical segment as the client, you have NO way of taking an IP and getting the MAC (or vice/versa).
如果其他网络上没有某些东西(或客户端本身),您就无法做到这一点。
MAC 地址用于OSI 网络模型的第二层,即数据链路层。 MAC 是以太网特有的。当您访问 Internet 时,会使用 IP 地址。并非所有连接到互联网的设备都在较低层使用以太网。
除了 IP 之外,还可以使用其他协议。
基本上,您的计算机只知道其物理网段上的内容。如果它必须出去做其他事情,它只知道到达那里的网关的 MAC。
You can't, without having something (or the client itself) on that other network.
MAC addresses are used on the second layer, the data-link layer, of the OSI model for networking. MACs are specific to Ethernet. When you get to the Internet, IP addresses are used. Not everything connected to the Internet uses Ethernet at lower layers.
There are also other protocols other than IP that can be used.
Basically, your computer only knows what is on its physical network segment. If it has to go outside for anything else, it only knows the MAC of the gateway to get there.
ARP 表的工作就是保存该信息。最好的办法就是从那里读出来。
您可以考虑阅读查询 ARP 缓存以获取 MAC ID 的答案。提问者使用的是Java,但除此之外它与你的问题相同。
It is the ARP table's job to keep that information. The best thing to do would be to read it out of there.
You might consider reading the answers to Query ARP cache to get MAC ID. The questioner was using Java, but otherwise its your identical question.