Discussion:
How to get remote MAC
(too old to reply)
AndyW
2007-08-15 16:07:48 UTC
Permalink
Is there any way to get the MAC address associated with a socket? I know
SendARP can be used to get the MAC address associated with an IP address,
but what will it return if multiple clients are using the same IP address?
I need to be able to uniquely identify the client in this case, is there
something besides the MAC that would be unique?

Thanks in advance,
Andy
TarasCo
2007-08-16 09:27:17 UTC
Permalink
I dont think that is good idea. It will work if all of your client is
situated in the same subnet, else you get gateway's MAC address.
AndyW
2007-08-16 12:15:46 UTC
Permalink
Post by TarasCo
I dont think that is good idea. It will work if all of your client is
situated in the same subnet, else you get gateway's MAC address.
The clients are all on the same subnet
Ben Voigt [C++ MVP]
2007-08-16 14:12:02 UTC
Permalink
Post by AndyW
Is there any way to get the MAC address associated with a socket? I know
SendARP can be used to get the MAC address associated with an IP address,
but what will it return if multiple clients are using the same IP address?
I need to be able to uniquely identify the client in this case, is there
something besides the MAC that would be unique?
Sockets are associated to (sender IP, dest IP, sender port, dest port)
tuple. If you have multiple clients using the same IP address (that's
called a conflict!) then winsock will see only one connection and everything
will be badly confused.
Post by AndyW
Thanks in advance,
Andy
AndyW
2007-08-16 19:20:20 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Post by AndyW
Is there any way to get the MAC address associated with a socket? I know
SendARP can be used to get the MAC address associated with an IP address,
but what will it return if multiple clients are using the same IP
address? I need to be able to uniquely identify the client in this case,
is there something besides the MAC that would be unique?
Sockets are associated to (sender IP, dest IP, sender port, dest port)
tuple. If you have multiple clients using the same IP address (that's
called a conflict!) then winsock will see only one connection and
everything will be badly confused.
Post by AndyW
Thanks in advance,
Andy
I understand that, but there is nothing preventing someone from doing
something stupid (like using hte same IP address on 2 systems). On the
otherhand, it is difficult and uncommon to modify the MAC address, which is
why I would like to get it. I suppose an alternate question would be is
there a way to get the MAC address associated with a specific IP address and
port? It looks like SendARP only uses the IP address, which I assume will
return the MAC of the last system that it saw with the given IP address, so
all bets are off if 2 systems are using hte same address.
Ben Voigt [C++ MVP]
2007-09-11 00:54:46 UTC
Permalink
Post by AndyW
I understand that, but there is nothing preventing someone from doing
something stupid (like using hte same IP address on 2 systems). On the
otherhand, it is difficult and uncommon to modify the MAC address, which
is why I would like to get it. I suppose an alternate question would be
is there a way to get the MAC address associated with a specific IP
address and port? It looks like SendARP only uses the IP address, which I
assume will return the MAC of the last system that it saw with the given
IP address, so all bets are off if 2 systems are using hte same address.
The ARP table holds the mapping from IP address to MAC address. The port
isn't considered at all. You can "lock" the mapping by creating a static
entry in the ARP table, then no matter who else uses that IP address, your
system will ignore them.

BTW it is not at all difficult to modify the MAC address, Windows has a
textbox for it in the Network Adapter configuration on the Advanced tab
(with most cards, a few drivers don't support it).

Loading...