NetworkInterface.GetPhysicalAddress 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回這個介面卡的媒體存取控制 (MAC) 或實體位址。
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
傳回
PhysicalAddress 物件,包含實體位址。
範例
下列程式代碼範例會顯示本機計算機上所有介面的實體位址。
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
備註
這個方法所傳回的物件包含適用於用來在數據連結層傳輸數據之媒體的位址。 例如,在乙太網路上,這個方法會傳回乙太網路硬體位址。