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 实例。 返回值指示转换是否成功。

适用于