
Getting the MAC and IP address in .net
March 27, 2011It 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