Click here to Skip to main content
15,885,117 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,
i trying to get mac address of client machine but when i upload on server i am getting server mac address instead of client mac address.
plz any solution for this problem.
i want client mac address.

thanks

What I have tried:

public string GetMACAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
}
return sMacAddress;


}
Posted
Updated 31-May-16 20:47pm
Comments
Mehdi Gholam 1-Jun-16 2:09am    
You can only get the client MAC if the client sends it to you (which will normally not happen).
Sergey Alexandrovich Kryukov 1-Jun-16 2:25am    
Why would you even need such internal detail of the client system? Web application don't have access to client systems, by pretty obvious reasons.
—SA
Member 10852141 1-Jun-16 2:38am    
because our client want only specific user access portal and only on one PC..
Sergey Alexandrovich Kryukov 1-Jun-16 2:42am    
You are looking in wrong direction. You already got the answer: you cannot do it.

You can do something different. For example, you can use the solution based purely on administration. You can make that PC a member of corporate network where your Web application or a site is served up, or something like that, depending on the purpose.

—SA

1 solution

You cannot get the Client MAC address in 99.99% of circumstances - basically you can only retrieve it if the client is running IE and has ActiveX enabled - which it isn't by default. The MAC address does not get passed through the router to the internet, an IP address is used instead.
It appeared to work on your development machine because they clinet and server were the same machine, so when you returned the MAC, you got the server address which happened to be the same as the Client. C# code always runs on the server, so it always retrieves server information.
 
Share this answer
 
Comments
Member 10852141 1-Jun-16 2:54am    
I agree but how i get mac of client mac address..so that other user not allow to login..
OriginalGriff 1-Jun-16 3:01am    
You can't.
If you could, then banks, PayPal, even Farcebook would be using it (except MACs are trivial to spoof, aren't unique, and so it wouldn't work anyway) - and criminals would be reading it as well and pretending to be you! :laugh:
"Unique ID" is a problem on the internet, which no-one has solved - but MAC wouldn't do it if it even if the system allowed you to access it.
About all you can do is put a cookie on the system which "registers" that machine to that user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900