2

the code :

var macAddr =
      (from nic in NetworkInterface.GetAllNetworkInterfaces()
       where nic.OperationalStatus == OperationalStatus.Up
       select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

the output :

0800275283A8

how covert to :

08:00:27:52:83:A8

JanR
  • 6,052
  • 3
  • 23
  • 30
abdo
  • 58
  • 4

1 Answers1

4

Try this:

 var macAddr =
              (from nic in NetworkInterface.GetAllNetworkInterfaces()
               where nic.OperationalStatus == OperationalStatus.Up
               select nic.GetPhysicalAddress().GetAddressBytes()).FirstOrDefault();

 string formattedMacAddr = string.Join (":", (from z in macAddr select z.ToString ("X2")).ToArray());
 Console.WriteLine(formattedMacAddr);

//outputs this format: 08:00:27:52:83:A8
JanR
  • 6,052
  • 3
  • 23
  • 30