h1

Getting the MAC and IP address in .net

March 27, 2011

It took me forever to find this information and the solution was extremely simple. The System.Net.NetworkInformation namespace provides network card information.

static void Main(string[] args)
{
  NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces().Where(a=> a.OperationalStatus.Equals( OperationalStatus.Up)).FirstOrDefault();
  string macAddress = networkInterface.GetPhysicalAddress().ToString();
  string clientIp = networkInterface.GetIPProperties().UnicastAddresses[0].Address.ToString();
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.