查找MAC来自IP地址 [英] Finding MAC address from IP

查看:186
本文介绍了查找MAC来自IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:

  得到远程主机的的MAC地址

我的工作有一个客户服务器架构的模块。我必须连接等机器的MAC地址的基础上进行验证。

I'm working on a module which has a client server architecture. And i have to authenticate the connecting peer machine on the basis of Mac address.

在安装的时候我存储有效的MAC地址列表加密

At the time of installation i store a encrypted list of valid Mac addresses.

请注意,我有这样的同行机上没有控制和一些第三方应用程序将在此运行,我不能安装此对等机上的任何应用程序。

目前,当套接字连接发生了,我需要知道的MAC ID为连接使用的IP,这样我就可以验证这对pviously存储在$ P $运行时的MAC地址。

At run time when socket connection happens i need to know the Mac Id for the IP used in connection, so that i can validate it against the previously stored Mac address.

是否有任何C / C ++ API可用它可以帮助我从IP地址获取MAC地址。
这个M / C通常被连接在一个局域网,但可以在不同的子网。

Are there any C/C++ API available which can help me to get mac address from the ip address. This m/c usually be connected in a LAN but can be on different subnets.

我的模块是多平台和运行在Windows,Solaris和Linux和类似的同行M / C可以在任何操作系统上运行。

My module is multiplatform and runs on windows , Solaris and Linux and the similarly the peer m/c can be running on any os.

推荐答案

不幸的是,简单的答案是真的不这样做。

Unfortunately, the simple answer is really "don't do that".

如果您对机器不同的子网(因此你和同行正在通过一个路由器之间的通信量),那么有没有办法做你想做什么 - 你接收到数据包的MAC地址将是其中他们转发给你们,因为这是你与通信链路层设备路由器的MAC地址。只有最接近同行机路由器会知道对方的MAC地址是什么 - 这个信息不传递

If your peer machines are on a different subnet (and therefore traffic between you and the peer is passing through a router), then there's no way to do what you want -- the MAC address of the packets you receive will be the MAC address of the router which forwarded them to you, as that's the link-layer device you're communicating with. Only the router nearest to the peer machine will know what the MAC address of the peer is -- and this information isn't passed on.

如果对等机器都在同一个子网,那么进入的数据包将包含以太网头端的MAC地址,...但在将数据包传送到你的应用程序这个被扒掉。你的选择是pretty多局限在网络接口上或者数据包捕获你听上得到整个数据包,或使用任何工具,您的系统提供检查本地的ARP表中。这两个选项都非常依赖于平台的!

If the peer machines are on the same subnet, then the incoming packets will contain the MAC address of the peer in the Ethernet header... but this gets stripped off before the packet is delivered to your application. Your options are pretty much limited to either packet-capturing on the network interface you're listening on to get the entire packet, or using whatever tools your system provides to check the local ARP table. Both of these options are very platform-dependent!

此外,这两个选项很可能继续不加修改工作,如果你处理的接口不是以太网接口(也许他们PPP链路,或WiFi,或某种时髦的虚拟接口,... ),也不会与IPv6的工作。

Also, neither option is likely to continue working without modification if the interfaces you're dealing with aren't Ethernet interfaces (perhaps they're PPP links, or WiFi, or a funky virtualized interface of some sort, ...), nor will they work with IPv6.

如果这一切之后,你仍然决定,考虑 libpcap的 /的WinPCap 的数据包捕获,这是一个想到的最便携的选择。要检查本地的ARP表,Linux和OS X,Solaris和Windows都提供了一个 ARP 命令行实用工具,但语法可能有所不同。如果API可用,我不希望在平台之间通用的任何 - 有对这种事情没有标准,因为你真的不应该这样做。

If after all that, you're still determined, look into libpcap/WinPCap for packet capturing, which is the most portable option which comes to mind. To check the local ARP tables, Linux, OS X, Solaris and Windows all provide an arp command-line utility, but the syntax is likely to vary. If an API is available, I wouldn't expect any commonality between the platforms -- there's no standard for this sort of thing, because you really shouldn't be doing it!

这篇关于查找MAC来自IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆