NetworkInterface.GetPhysicalAddress Methode

Definitie

Retourneert de Media Access Control (MAC) of het fysieke adres voor deze adapter.

public:
 abstract System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public:
 virtual System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public abstract System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress();
public virtual System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress();
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
override this.GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
Public MustOverride Function GetPhysicalAddress () As PhysicalAddress
Public Overridable Function GetPhysicalAddress () As PhysicalAddress

Retouren

Een PhysicalAddress object dat het fysieke adres bevat.

Voorbeelden

In het volgende codevoorbeeld worden de fysieke adressen van alle interfaces op de lokale computer weergegeven.

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();
      }
   }
Public Shared Sub DisplayTypeAndAddress() 
    Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    Console.WriteLine("Interface information for {0}.{1}     ", computerProperties.HostName, computerProperties.DomainName)
    Dim adapter As NetworkInterface
    For Each adapter In  nics
        Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
        Console.WriteLine(adapter.Description)
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, "="c))
        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)
    Next adapter

End Sub

Opmerkingen

Het object dat door deze methode wordt geretourneerd, bevat een adres dat geschikt is voor de media die worden gebruikt voor het transport van gegevens op de gegevenskoppelingslaag. Op een Ethernet-netwerk retourneert deze methode bijvoorbeeld het Ethernet-hardwareadres.

Van toepassing op