Hi,
I want to write code for getting mac address.
I used Imports System.Management, but it said that it is not defined. Pls help me out.
Used: VB .net 2005 pro
Thanks
Hi,
I want to write code for getting mac address.
I used Imports System.Management, but it said that it is not defined. Pls help me out.
Used: VB .net 2005 pro
Thanks
get Mac address
ShareCropper
Thanks David. It was helpful.
As I am using .Net 2.0 (c#) using your above comment following code did return exactly what I was looking for.
Using Microsoft Help for "System.Net.NetworkInformation.NetworkInterface" class & suggested method (GetAllNetworkInterfaces() , GetPhysicalAddress()) searched MSDN & it had example returning MAC address.
public static void DisplayTypeAndAddress() { IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName); foreach (NetworkInterface adapter in nics) { IPInterfaceProperties properties = adapter.GetIPProperties(); Console.WriteLine(adapter.Description); Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'=')); Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType); Console.WriteLine(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString()); Console.WriteLine(" Is receive only.......................... : {0}", adapter.IsReceiveOnly); Console.WriteLine(" Multicast................................ : {0}", adapter.SupportsMulticast); } }Note: For "IPGlobalProperties " you need to add refrence to "using System.Net.NetworkInformation;"
nildorn
Have a look at the System.Net.NetworkInformation.NetworkInterface class.
It has a shared (static in C#) member called GetAllNetworkInterfaces() that returns an array on NetworkInterface classes that represent available network connections.
The NetworkInterface class has a method called GetPhysicalAddress() that returns the MAC address.