开发者

Easiest way to get MAC address from a (non-local) IP address in IPv4

开发者 https://www.devze.com 2023-02-17 06:10 出处:网络
Is there an easy way to get a MAC address of a machine c开发者_开发技巧onnected to my app via a TCP/IPv4 socket?

Is there an easy way to get a MAC address of a machine c开发者_开发技巧onnected 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?


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


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.


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.

0

精彩评论

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

关注公众号