Articles → .NET → Get MAC address of the system in C#

Get MAC address of the system in C#





using System;
using System.Net.NetworkInformation;

namespace GetMacAddress
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            String sMacAddress = string.Empty;
            foreach (NetworkInterface adapter in nics)
            {
                if (sMacAddress == String.Empty)// only return MAC Address from first card  
                {
                    IPInterfaceProperties properties = adapter.GetIPProperties();
                    sMacAddress = adapter.GetPhysicalAddress().ToString();
                }
            }
            Console.WriteLine(sMacAddress);
        }
    }
}



Posted By  -  Karan Gupta
 
Posted On  -  Friday, March 10, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250