So far I have the following Elixir code
{:ok, server_socket} = :gen_tcp.listen(port)
{:ok, client_socket} = :gen_tcp.accept(server_socket)
How can I get the MAC address from the client_socket
?
P.S. I know that the MAC address is changed every hop, but my network ensures that there's only one hop from the client to the server so if I can get the MAC address, that's definitely the client's.
Erlang provides :inet.getifaddrs/0
to get a list of interface names and their addresses, but there is no out-of-the-box method that will allow you to get the mac address of the connected host or router, from a socket.
The problem is that the TCP is independent of any MAC level protocols. In practice, when using the ethernet link layer, the TCP stack uses ARP to obtain the MAC of the connected host or router.
A few possible solutions are:
ioctl SIOCGARP
via some C
codeSystem.cmd
to get the result of a shell program like arp