Formatting MAC address in C#

后端 未结 5 1223
灰色年华
灰色年华 2020-12-06 10:35

In my C# application, I want to get my MAC address by using NetworkInterface class as the following:

NetworkInterface nic in NetworkInterface.Ge         


        
5条回答
  •  情话喂你
    2020-12-06 11:23

    Using the comment by eFloh for using BitConverter I was able to do the following (assuming mac is predefined as a string).

    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
    {
        mac = BitConverter.ToString(nic.GetPhysicalAddress().GetAddressBytes()).Replace('-', ':');
    
        //Do whatever else necessary with each mac...
    }
    

提交回复
热议问题