Skip to content

Instantly share code, notes, and snippets.

@javagg
Created June 17, 2014 13:08
Show Gist options
  • Save javagg/f02b4058ba757bdf2da3 to your computer and use it in GitHub Desktop.
Save javagg/f02b4058ba757bdf2da3 to your computer and use it in GitHub Desktop.
Get Mac Address in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
var mac = string.Join(":", nic.GetPhysicalAddress().GetAddressBytes().Select(b => b.ToString("X2")));
Console.WriteLine(mac);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment