13

I'm trying to get mac address from the client's machine that browse my web site, I've been used this:

using System.Management;
class Sample_ManagementClass
{
    public static int Main(string[] args)
    {
        ManagementClass objMC = new
        ManagementClass("Win32_NetworkAdapterConfiguration");
        ManagementObjectCollection objMOC = objMC.GetInstances();

        foreach (ManagementObject objMO in objMOC)
        {
            if (!(bool)objMO["ipEnabled"])
                continue;

            Console.WriteLine((string)objMO["MACAddress"]);
        }
    }
 }

But it is not recognized Management Namespace, so what should I do?

1
  • 3
    Are you actually expecting the client's MAC address to be available through the WMI provider of the server? Commented Jan 6, 2012 at 10:11

2 Answers 2

19

it's unfortunately not possible to reliably get the mac address of the client machine due to firewalls, proxies and ISP generic addresses being given. However, you can make a stab at getting the ip address by using:

var remoteIpAddress = Request.UserHostAddress;

However, this may or may not actually represent the client machine and is more likely the ISP gateway or some other ip address. It's a well known problem and one that even google have found hard to crack using clientside javascript (the idea here being that you get the actual local ip address via a js library and pass that over to your server function).

[edit] - might be worth taking a look at the following for inspiration/confirmation of the issue:

http://www.dotnetfunda.com/forums/thread2088-how-to-get-mac-address-of-client-machine.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

it's not possible to get the mac address of the client because it's on the ethernet physical layer, so if there is no direct physical link between your web site and the client ... it's not due to firewall
possible to get the MAC of iis where the website is hosted?
5

It is usually not possible for a person to get the MAC address of a computer from its IP address alone. These two addresses originate from different sources. Simply stated, a computer's own hardware configuration determines its MAC address while the configuration of the network it is connected to determines its IP address. However, computers connected to the same TCP/IP local network can determine each other's MAC addresses. The technology called ARP - Address Resolution Protocol included with TCP/IP makes it possible. Using ARP, each computer maintains a list of both IP and MAC addresses for each device it has recently communicated with.

Src

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.