Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm developing a ASP.Net website. For User Tracking we need to register the Mac Address of the Client Machines where the User logging in. I have tried two methods. but in both methods it is taking server mac address instead of client machine.

Please, anyone help me, to get mac address of the client machine. thanks in advance.

What I have tried:

First Method
-------------

public string GetMACAddress()
{
var macAddr =
(from nic in NetworkInterface.GetAllNetworkInterfaces()
where nic.OperationalStatus == OperationalStatus.Up
select nic.GetPhysicalAddress().ToString()).FirstOrDefault();
return macAddr;
}

Second Method
-------------
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up && (!nic.Description.Contains("Virtual") && !nic.Description.Contains("Pseudo")))
{
if (nic.GetPhysicalAddress().ToString() != "")
{
mac = nic.GetPhysicalAddress().ToString();
}
}
}
Posted
Updated 18-Jun-18 9:05am
Comments
F-ES Sitecore 18-Jun-18 11:13am    
This is a very frequently asked question, please do basic research like using google before asking a question and you would have got your answer in seconds.

Simple, you can't.

The MAC address isn't visible, nor has any meaning, to anything but the subnet the client machine is on.

It cannot be used to uniquely identify a machine, since it's NOT a unique value and has nothing to do with the machine. It's an identifier for a network interface, not a machine since machines can have multiple network interfaces.

The code you've posted only works to get the MAC of one of the network interfaces in the SERVER, NOT THE CLIENT! ASP.NET code runs entirely on the server, never the client.
 
Share this answer
 
The "user" "sends" a / the MAC address when logging in / registering with the server.

The MAC refers to a NIC; a network interface card.

The MAC identifies the vendor; and the vendors product identification system.

A Vendor may have multiple "vendor Ids"; even for the same type of equipment.
 
Share this answer
 
As others have mentioned, there is no real fool-proof way of identifying a particular device in a web application. You are only going to get the gateway's IP address/MAC.

I recently had a web application that had the same requirements to identify devices for record keeping. We came up with a method that encodes the device name and a couple of other key elements into the querystring used to launch the app. Once a device has been validated the appropriate cookies are also written/rewritten to the client...but you can't trust cookies. This system is working well for a customer having around 50 iPads/locations. As usual, session timeouts are the devil...code accordingly!

One other possibility is creating a hybrid application that is basically a Click-Once windows application that contains a single form containing a browser control. On startup, get the systems mac address and/or device name, logged in user name, etc. and pass this in through the querystring to your web application. I've been using this method for a few years now for a couple of different clients and it works fine...it just limits you to windows devices.
 
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