DuplicateAddressDetectionState 枚举

定义

指定 IP 地址的当前状态。

C#
public enum DuplicateAddressDetectionState
继承
DuplicateAddressDetectionState

字段

名称 说明
Deprecated 3

此地址有效,但它的租约期限已快到期,应用程序不应使用它。

Duplicate 2

此地址不是唯一的。 此地址不应分配给网络接口。

Invalid 0

此地址无效。 无效的地址已过期,不再被分配给接口,应用程序不应将数据包发送到此地址。

Preferred 4

此地址有效而且它的使用是无限制的。

Tentative 1

此地址的重复地址检测过程评估没有成功完成。 应用程序不应使用此地址,因为此地址已无效,发送给它的数据包将被丢弃。

示例

下面的代码示例确定单播地址信息。

C#
public static void DisplayUnicastAddresses()
{
    Console.WriteLine("Unicast Addresses");
    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        UnicastIPAddressInformationCollection uniCast = adapterProperties.UnicastAddresses;
        if (uniCast.Count >0)
        {
            Console.WriteLine(adapter.Description);
            string lifeTimeFormat = "dddd, MMMM dd, yyyy  hh:mm:ss tt";
            foreach (UnicastIPAddressInformation uni in uniCast)
            {
                DateTime when;

                Console.WriteLine("  Unicast Address ......................... : {0}", uni.Address);
                Console.WriteLine("     Prefix Origin ........................ : {0}", uni.PrefixOrigin);
                Console.WriteLine("     Suffix Origin ........................ : {0}", uni.SuffixOrigin);
                Console.WriteLine("     Duplicate Address Detection .......... : {0}",
                    uni.DuplicateAddressDetectionState);

                // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
                // if en-us is the current culture.

                // Calculate the date and time at the end of the lifetimes.
                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     Valid Life Time ...................... : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );
                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     Preferred life time .................. : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );

                when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime);
                when = when.ToLocalTime();
                Console.WriteLine("     DHCP Leased Life Time ................ : {0}",
                    when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
                );
            }
            Console.WriteLine();
        }
    }
}

注解

为了帮助确保网络上的所有接口都有唯一的地址,接口主机负责对单播地址运行“重复地址检测”算法。 此算法的目的是尝试阻止网络上不唯一的地址。 此过程在 IETF RFC 1971 中定义。

和 类使用此UnicastIPAddressInformationMulticastIPAddressInformation枚举。 检索对象的单播地址信息时,将返回此类的 NetworkInterface 实例。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1