开发者

How to get the IP address of a remote host from its Ethernet address?

开发者 https://www.devze.com 2022-12-24 15:52 出处:网络
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...http://compnetworking.a

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...


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号