PhysicalAddress 類別

定義

提供網路介面(介面卡)的媒體存取控制(MAC)位址。

public ref class PhysicalAddress
public class PhysicalAddress
type PhysicalAddress = class
Public Class PhysicalAddress
繼承
PhysicalAddress

範例

以下程式碼範例顯示了本地電腦上所有介面的實體位址。

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 方法回傳。

建構函式

名稱 Description
PhysicalAddress(Byte[])

初始化 PhysicalAddress 類別的新執行個體。

欄位

名稱 Description
None

回傳 PhysicalAddress 一個長度為零的新實例。 此欄位僅供讀取。

方法

名稱 Description
Equals(Object)

比較兩個 PhysicalAddress 案例。

GetAddressBytes()

回傳目前實例的位址。

GetHashCode()

回傳實體位址的雜湊值。

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 例。 傳回值表示轉換是否成功。

適用於