Ashish Vala
Ashish Vala

Reputation: 11

How to get MAC Address of client?

I am trying to get the MAC address of the client pc but it shows the mac address of the IIS server where my project is hosted.

protected void Page_Load(object sender, EventArgs e)
    {
        NetworkInterface[] anics = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface adapter in anics)
        {
            if (amacaddress == String.Empty)
            {
                IPInterfaceProperties properties = adapter.GetIPProperties();
                amacaddress = adapter.GetPhysicalAddress().ToString();
                lblname.Visible = true;
                string ip = Request.UserHostAddress;

                lblname.Text = "MAC Address is :- " + amacaddress + "  "+ ip;
            }
        }
    }

Upvotes: 0

Views: 3540

Answers (1)

TomTom
TomTom

Reputation: 62093

Yeah. That is similar to asking for getting the IMSI of a phone from a phone call - not possible, you call a phone number, the rest is implementation detail. MAC Addresses pretty much never travel more than one ethernet domain (next switch/router). They are not pat of the IP protocol layer. As such, you can not get them from the http request, which ultimatly is a TCP thus an IP connection. YOu will have to execute (C#, not javascript) code on the client to possibly get the local MAC AddressES - that is plural, there may be more than one (as in: 2 local network cards, a wireless adapter = 3 mac addresses).

Upvotes: 2

Related Questions