Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Requirement is, the user should log in from specific system. For this I am saving client PC's MAC Address into my database. When user will try to login, the web application should get MAC ID of Client PC and verify with database value. If it matches, user will be allowed to log in. Is it possible to read client PC's MAC id through WMI Object?

What I have tried:

var macAddress = "";
var ipAddress = "";
var computerName = ".";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate, (Systemtime)}!//" + computerName + "/root/cimv2");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for (; !e.atEnd() ; e.moveNext()) {
var s = e.item();
macAddress = s.MACAddress;
ipAddress = s.IPAddress(0);
computerName = s.DNSHostName;
}
Posted
Updated 25-Sep-17 4:03am
Comments
Kornfeld Eliyahu Peter 25-Sep-17 8:43am    
And what will you do if client comes from a non-Windows OS (like mobile)?
You better check how to use a client-certificate...
F-ES Sitecore 25-Sep-17 9:40am    
Google "get client mac address asp.net" and you'll see the answer to this very frequently asked question never changes.

1 solution

You can't do this. Access to client hardware is off-limits to the code running on the server (ASP.NET) and to code running in the browser (javascript).

Also, A MAC Address is NOT unique to a system. MAC's are unique to a network interface on a network subnet.

You CAN have multiple NIC's with the same MAC address accessing your site from various locations around the world, in the same cities, in the same companies, even inside your company premises.

What about the case where laptops have multiple NIC's, each with their own MAC? Yes, it's quite common. If a laptop is connected to a wired network, the MAC address is going to be different when they pull that cable out and switch to wireless network, or even drop the machine in a dock with it's own NIC and yet another MAC address.

To ID a machine, you'd need to install a certificate on the client. You'd probably have to have your own certificate server dolling these out too.

If that's a little much, generate a GUID value and send that to the client to store in a cookie. Yes, cookies can be cleared, so that's something you'd have to evaluate for yourself to see if its acceptable.
 
Share this answer
 

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