Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

MAC address and Network Interface Description

, 28 Jan 2014
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Vinayak Hegde (Vinnie)
Software Developer IBI Limited
United Kingdom United Kingdom
Being a human - I am a Coder, a Blogger, a Tweeter, a Son, a Brother and a human being..
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionMethod signature PinprofessionalJV999929-Jan-14 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 28 Jan 2014
Article Copyright 2014 by Vinayak Hegde (Vinnie)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid