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