Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
How to find the MAC Id of Client Machine
Posted 13-Mar-12 2:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

using System.Net.NetworkInformation
 

private void Form15_Load(object sender, EventArgs e)
      {
         
          NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
 
          label1.Text = nics[0].GetPhysicalAddress().ToString();
 
      }
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
easy to achieve with WMI. Try this:
 
private string GetMac()
{
    string Mac = string.Empty;
    ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
    ManagementObjectCollection MOCol = MC.GetInstances();
    foreach (ManagementObject MO in MOCol)
        if (MO != null)
        {
           if (MO["MacAddress"] != null)
                    {
                         Mac = MO["MACAddress"].ToString();
                         if (Mac != string.Empty)
                             break;
                    }
        }
    return Mac;
}
 
Regards
  Permalink  
v2
Comments
Björn Ranft at 13-Mar-12 8:25am
   
This is a full working code sample, just copy/paste it. You need a reference to System.Management Class. Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 1 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid