This documentation is archived and is not being maintained.

NetworkInterface.GetPhysicalAddress Method

Returns the Media Access Control (MAC) or physical address for this adapter.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public abstract PhysicalAddress GetPhysicalAddress()

Return Value

Type: System.Net.NetworkInformation.PhysicalAddress
A PhysicalAddress object that contains the physical address.

The object returned by this method contains an address that is appropriate to the media used to transport data at the data link layer. For example, on an Ethernet network, this method returns the Ethernet hardware address.

The following code example displays the physical addresses of all interfaces on the local computer.

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);
        Console.WriteLine();
      }
   }
void DisplayTypeAndAddress()
{
    IPGlobalProperties* computerProperties = IPGlobalProperties::GetIPGlobalProperties();
    NetworkInterface* nics[] = NetworkInterface::GetAllNetworkInterfaces();
    Console::WriteLine(S"Interface information for {0}.{1}     ",
        computerProperties->HostName, computerProperties->DomainName);
    System::Collections::IEnumerator* myEnum27 = nics->GetEnumerator();
    while (myEnum27->MoveNext())
    {
        NetworkInterface* adapter = __try_cast<NetworkInterface*>(myEnum27->Current);
        IPInterfaceProperties* properties = adapter->GetIPInterfaceProperties();
        Console::WriteLine(adapter->Description);
        Console::WriteLine(String::Empty->PadLeft(adapter->Description->Length,'='));
        Console::WriteLine(S"  Interface type .......................... : {0}", __box(adapter->Type));
        Console::WriteLine(S"  Physical Address ........................ : {0}", 
            adapter->GetPhysicalAddress());
        Console::WriteLine(S"  Is receive only.......................... : {0}", __box(adapter->IsReceiveOnly));
        Console::WriteLine(S"  Multicast................................ : {0}", __box(adapter->SupportsMulticast));
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: