NetworkInterface.GetPhysicalAddress Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne l'adresse MAC (Media Access Control) ou physique de cet adaptateur.
public:
virtual System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public:
abstract System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public virtual System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress ();
public abstract System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress ();
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
override this.GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
Public Overridable Function GetPhysicalAddress () As PhysicalAddress
Public MustOverride Function GetPhysicalAddress () As PhysicalAddress
Retours
Objet PhysicalAddress qui contient l'adresse physique.
Exemples
L’exemple de code suivant affiche les adresses physiques de toutes les interfaces sur l’ordinateur local.
void DisplayTypeAndAddress()
{
IPGlobalProperties ^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
Console::WriteLine( "Interface information for {0}.{1} ", computerProperties->HostName, computerProperties->DomainName );
System::Collections::IEnumerator^ myEnum27 = nics->GetEnumerator();
while ( myEnum27->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum27->Current);
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() );
Console::WriteLine( " Is receive only.......................... : {0}",
adapter->IsReceiveOnly );
Console::WriteLine( " Multicast................................ : {0}",
adapter->SupportsMulticast );
}
}
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
Remarques
L’objet retourné par cette méthode contient une adresse appropriée au média utilisé pour transporter des données au niveau de la couche de liaison de données. Par exemple, sur un réseau Ethernet, cette méthode retourne l’adresse matérielle Ethernet.