Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

MAC address and Network Interface Description

0.00/5 (No votes)
28 Jan 2014 1  
Finds the mac address and description of network interface

Introduction

A Console Application that shows the MAC addresses and description of that Network interface card. This is for beginners who wants a quick solution for finding their MAC address.

Background 

MAC address (media access control address) is a unique identifier assigned to network interfaces for communications on the physical network segment. MAC addresses are used as a network address for most IEEE 802 network technologies, including Ethernet. Logically, MAC addresses are used in the media access control protocol sublayer of the OSI reference model.

MAC addresses are most often assigned by the manufacturer of a network interface controller (NIC) and are stored in its hardware, such as the card's read-only memory or some other firmwaremechanism. If assigned by the manufacturer, a MAC address usually encodes the manufacturer's registered identification number and may be referred to as the burned-in address (BIA). It may also be known as an Ethernet hardware address (EHA), hardware address or physical address. This can be contrasted to a programmed address, where the host device issues commands to the NIC to use an arbitrary address.

A network node may have multiple NICs and each must have one unique MAC address per NIC. 

Reference: Wikipedia  

Using the code 

The code is very simple, where a method GetMyMacAddress() returns a list of type string. Make sure to use the namespace "System.Net.NetworkInformation" - you can loop through NetworkInterface where it has the member method GetAllNetworkInterfaces().

Physical address can be retrieved from GetPhysicalAddress(). 

    private static List<string> GetMyMacAddress()
    {
        List<String> slistMac = new List<string>();

        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            PhysicalAddress address = nic.GetPhysicalAddress();
            if ((NetworkInterfaceType.Tunnel != nic.NetworkInterfaceType) 
                 && !String.IsNullOrEmpty(address.ToString()))
            {
                string sMac = string.Join(":", (from z in nic.GetPhysicalAddress()
                     .GetAddressBytes() select z.ToString("X2")).ToArray());
                slistMac.Add(String.Format("{0}\t {1}", sMac, nic.Description));

            }
        }
        return slistMac;
    }
  Then you can display MAC by calling GetMyMacAddress() in your main Method
 foreach (string sMac in GetMyMacAddress())
            Console.WriteLine(sMac);
  

History 

This is the first version, Next could be display MAC using WPF..!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here