বুধবার, ৩০ নভেম্বর, ২০১১

Get MAC Address using C#

Add the reference System.Management and Import System.Management namespace.
Get the Mac address of all network cards in the machine 

protected void GetMACAddress()
{
    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection moc = mc.GetInstances();
    string MACAddress = "";
    foreach (ManagementObject mo in moc)
    {                
        if (mo["MacAddress"] != null)
        {                    
            MACAddress = mo["MacAddress"].ToString();
            MessageBox.Show(MACAddress);
        }                                
    } 
}
 
Get the Mac address of network card is being used in the machine
 
protected void GetMACAddress()
{ ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); string MACAddress = ""; foreach (ManagementObject mo in moc) { if (mo["MacAddress"] != null) { if ((bool)mo["IPEnabled"] == true) { MACAddress = mo["MacAddress"].ToString(); MessageBox.Show(MACAddress); } } } }

  
 Output:


কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন