Wednesday, August 3, 2016

Read MAC Address using asp.net

using  System.Management;


protected void Page_Load(object sender, EventArgs e)
    {
        string MacAdd = GetMACAddress();
        Response.Write("Mac Address is : " + MacAdd);
    }

   public string GetMACAddress()
    {
      ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguratin");
        ManagementObjectCollection moc = mc.GetInstances();
        string MacAdd = String.Empty;
        foreach (ManagementObject mo in moc)
        {
            if (MacAdd == String.Empty)
            {
                if ((bool)mo["IPEnabled"] == true) MacAdd = mo["MacAddress"].ToString();
            }
            mo.Dispose();
        }

        MacAdd = MACAddress.Replace(":", "");
        return MacAdd;
    }


No comments: