如何从远程主机的以太网地址获取其IP地址?

发布于 2024-08-25 17:42:28 字数 75 浏览 12 评论 0原文

我正在寻找一些 Linux 代码来从以太网地址查找 IP 地址。我想我必须做一些反向 A​​RP 欺骗,但我没有找到任何例子......

I'm looking for some Linux code to find an IP address from an Ethernet address. I suppose I have to do some inverse ARP trickery but I don't find any example...

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

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

发布评论

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

评论(3

短暂陪伴 2024-09-01 17:42:28

http://compnetworking.about.com/od/networkprotocolsip/f/convertipmacadd。 htm

尝试发送 IP 广播(例如,如果您的子网为 ping 192.168.1.255 “nofollow noreferrer">192.168.1.0/24)来填充您的 ARP 缓存,然后使用 arp -a 将其全部吐出。

http://compnetworking.about.com/od/networkprotocolsip/f/convertipmacadd.htm

Try sending an IP broadcast (e.g. ping 192.168.1.255 if your subnet is 192.168.1.0/24) to prime your ARP cache, followed by arp -a to spit it all out.

请叫√我孤独 2024-09-01 17:42:28

对于与您通信过的计算机,您可以查看其 arp 条目。例如,这可以在 /proc/net/arp 中以文本格式获得。查找您知道但尚未通信过的 MAC 的 IP 地址要困难得多。从协议角度来看,最接近的匹配是 RARP,但它几乎从未使用过,因此您不太可能得到响应。

您始终可以扫描本地子网,以确保获得 arp 表的完整视图。例如,请参阅 fping 以了解执行此操作的有效方法。请注意,主机实际上不需要响应出现在 ARP 表中的相关 ping,因此即使存在本地防火墙等情况下,这也很有用。

For computers that you have communicated with, you can look at their arp entry. This is available in text format in /proc/net/arp for example. Finding an IP address for a MAC that you know but haven't communicated with is significantly more difficult. The closest match, protocol-wise, would be RARP but that's hardly ever in use so your are not likely to get a response.

You can always scan your local subnet to make sure you get a full view in your arp table. See for example fping for an efficient way to do this. Note that hosts don't actually need to respond to the pings in question to appear in the ARP table, so this is useful even in the presence of local firewalls etc.

帅的被狗咬 2024-09-01 17:42:28

看看 Thomas Habet 的 Arping。我还没有尝试过,但基本思想是使用 IP 标头中的广播目标 IP 地址将 ICMP Ping 网络数据包发送到有问题的 MAC 地址。只有具有指定 MAC 地址的主机才会回复,并且回复(通常)将包含其 IP 地址。它并不总是有效,但可能对你来说已经足够了。有关限制,请参阅项目自述文件。

Take a look at Thomas Habet's Arping. I've not tried it, but the basic idea is to send an ICMP Ping network packet to the MAC address in question using a broadcast destination IP address in the IP header. Only the host with the specified MAC address will reply and the reply will (usually) contain its IP address. It won't always work but it might be good enough for you. See the project readme for limitations.

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