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

构造函数

名称 说明
PhysicalAddress(Byte[])

初始化 PhysicalAddress 类的新实例。

字段

名称 说明
None

返回一个具有零长度地址的新 PhysicalAddress 实例。 此字段为只读。

方法

名称 说明
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 实例。 一个指示转换是否成功的返回值。

适用于