Getting physical address/ MACID of network device

G

Guest

Hi,

I am using an asynchronous socket server to allow comms between multiple
clients and my server. I know how to obtain the IPAddress of the client
(network device) as shown below :-

string sensorIPAddress =
((IPEndPoint)handler.RemoteEndPoint).Address.ToString();

but what I would like to obtain is the physical/MACID of the client.

Does anyone know how I can do this?

Thanks
Macca
 
G

Guest

The MACAddress of a client is not transmitted via normal socket operations,
unless you put in specific code on the client to retrieve and send this.
Peter
 
M

Mythran

Peter Bromberg said:
The MACAddress of a client is not transmitted via normal socket
operations,
unless you put in specific code on the client to retrieve and send this.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

Interesting. I have seen on routers that run as DHCP servers obtain the
client's mac address/id. How do they do this when they don't have any
software installed on the clients machine? Maybe it's just sent when the
DHCP server hands out the address...otherwise, how would the router know
which computer is what? :)

I dunno, just wonderin'.

Mythran
 
G

Goran Sliskovic

Mythran said:
....

Interesting. I have seen on routers that run as DHCP servers obtain the
client's mac address/id. How do they do this when they don't have any
software installed on the clients machine? Maybe it's just sent when
the DHCP server hands out the address...otherwise, how would the router
know which computer is what? :)

I dunno, just wonderin'.
....

MAC address exists at lower level (protocol stack). Sockets deal with IP
addresses (usually). MAC address is only known at local area network
where broadcast can travel (on the same broadcast domain). IOW, socket
does not have to deal with MAC address, somebody else will resolve
proper MAC address if needed. That is done by ARP protocol (address
resolution protocol). It is part of standard TCP/IP protocol stack that
is installed on windows.

If you type "arp -a" at command prompt, you'll see cached MAC addresses
and it's mapping to IP addresses.

Routers don't need anything on client machine to get MAC address, as it
is contained in every packet received from client and it can be parsed.

Please not that if packet comes through router, it's MAC address will be
MAC address of routers interface, not remote client. Also, IP address
that you get from socket may not be IP address of client, it may be
changed by NAT. It is always bad idea to add logic based on IP address
you obtained from socket.

Regards,
Goran
 
G

Guest

The MAC address is not available in the TCP protocol, it is through lower
level protocols in the communications stack. There are ways of getting the
MAC address, but you'll have to use Win32 API calls to do it. There are no
..NET Framework objects which expose it.

Also, you should know that MAC addresses are typically not routable and do
not survive hops across routers. If you are trying to grab the MAC address
of a machine somewhere over the Internet, you're not likely to get it.
You'll probably just get the MAC address of the nearest router.

-dM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top