Advertisement
ivandrofly

Get / Display mac addresses

Mar 16th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1.  public static string GetMacAddress(string separator = ":")
  2.         {
  3.             //System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
  4.             foreach (var ni in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
  5.             {
  6.                 var mac = ni.GetPhysicalAddress().ToString();
  7.  
  8.                 for (int i = mac.Length - 2; i > 0; i -= 2)
  9.                 {
  10.                     mac = mac.Insert(i, separator);
  11.                 }
  12.  
  13.                 Console.WriteLine($"Interface: {ni.Name} Mac {mac}");
  14.             }
  15.             string.Empty;
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement