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

女生的网名这么多〃 提交于 2021-01-20 11:32:21

问题


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?


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/5303652/easiest-way-to-get-mac-address-from-a-non-local-ip-address-in-ipv4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!