PhysicalAddress 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供網路介面 (介面卡) 的媒體存取控制 (MAC) 位址。
public ref class PhysicalAddress
public class PhysicalAddress
type PhysicalAddress = class
Public Class PhysicalAddress
- 繼承
-
PhysicalAddress
範例
下列程式代碼範例會顯示本機計算機上所有介面的實體位址。
void ShowNetworkInterfaces()
{
IPGlobalProperties^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
Console::WriteLine( L"Interface information for {0}.{1} ", computerProperties->HostName, computerProperties->DomainName );
if ( nics == nullptr || nics->Length < 1 )
{
Console::WriteLine( L" No network interfaces found." );
return;
}
Console::WriteLine( L" Number of interfaces .................... : {0}", (nics->Length).ToString() );
IEnumerator^ myEnum1 = nics->GetEnumerator();
while ( myEnum1->MoveNext() )
{
NetworkInterface^ adapter = safe_cast<NetworkInterface^>(myEnum1->Current);
IPInterfaceProperties^ properties = adapter->GetIPProperties();
Console::WriteLine();
Console::WriteLine( adapter->Description );
Console::WriteLine( String::Empty->PadLeft( adapter->Description->Length, '=' ) );
Console::WriteLine( L" Interface type .......................... : {0}", adapter->NetworkInterfaceType );
Console::Write( L" Physical address ........................ : " );
PhysicalAddress^ address = adapter->GetPhysicalAddress();
array<Byte>^bytes = address->GetAddressBytes();
for ( int i = 0; i < bytes->Length; i++ )
{
// Display the physical address in hexadecimal.
Console::Write( L"{0}", bytes[ i ].ToString( L"X2" ) );
// Insert a hyphen after each byte, unless we are at the end of the
// address.
if ( i != bytes->Length - 1 )
{
Console::Write( L"-" );
}
}
Console::WriteLine();
}
}
public static void ShowNetworkInterfaces()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
Console.WriteLine("Interface information for {0}.{1} ",
computerProperties.HostName, computerProperties.DomainName);
if (nics == null || nics.Length < 1)
{
Console.WriteLine(" No network interfaces found.");
return;
}
Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length);
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties(); // .GetIPInterfaceProperties();
Console.WriteLine();
Console.WriteLine(adapter.Description);
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, '='));
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType);
Console.Write(" Physical address ........................ : ");
PhysicalAddress address = adapter.GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
// Display the physical address in hexadecimal.
Console.Write("{0}", bytes[i].ToString("X2"));
// Insert a hyphen after each byte, unless we're at the end of the address.
if (i != bytes.Length - 1)
{
Console.Write("-");
}
}
Console.WriteLine();
}
}
備註
MAC 位址或實體位址是可唯一識別網路上每一個節點的硬體位址,例如計算機或印表機。
方法會傳 NetworkInterface.GetPhysicalAddress 回這個類別的實例。
建構函式
PhysicalAddress(Byte[]) |
初始化 PhysicalAddress 類別的新執行個體。 |
欄位
None |
傳回新的 PhysicalAddress 執行個體,其中含有長度為零的位址。 此欄位為唯讀。 |
方法
Equals(Object) |
比較兩個 PhysicalAddress 執行個體。 |
GetAddressBytes() |
傳回目前執行個體的位址。 |
GetHashCode() |
傳回實體位址的雜湊值 (Hash Value)。 |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
Parse(ReadOnlySpan<Char>) |
剖析指定的範圍,並將其內容儲存為此方法所傳回 PhysicalAddress 的位址位元組。 |
Parse(String) |
剖析指定的 String,並將其內容儲存為這個方法所傳回的 PhysicalAddress 之位址位元組。 |
ToString() |
傳回這個執行個體的位址之 String 表示。 |
TryParse(ReadOnlySpan<Char>, PhysicalAddress) |
嘗試將硬體位址的範圍表示法轉換為 PhysicalAddress 執行個體。 傳回指示轉換是否成功的值。 |
TryParse(String, PhysicalAddress) |
嘗試將硬體位址的字串表示法轉換為 PhysicalAddress 執行個體。 傳回指示轉換是否成功的值。 |