SuffixOrigin 列舉

定義

指定如何找到 IP 位址主機尾碼。

C#
public enum SuffixOrigin
繼承
SuffixOrigin

欄位

名稱 Description
LinkLayerAddress 4

尾碼是連結-本機尾碼。

Manual 1

尾碼是以手動方式設定。

OriginDhcp 3

尾碼是由動態主機設定通訊協定 (DHCP) 伺服器所提供。

Other 0

尾碼是使用未指定的來源來找到的。

Random 5

尾碼是以隨機方式指派。

WellKnown 2

尾碼是已知的尾碼。 已知的尾碼是在標準 Request for Comments (RFC) 文件中所指定,並由 Internet Assigned Numbers Authority (IANA) 或位址登錄所指派。 這類尾碼會保留供特殊目的使用。

範例

下列程式代碼範例會顯示單播位址的前置詞和後綴資訊。

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();
        }
    }
}

備註

IP 位址分成兩個部分:前置詞和後綴。 位址前置詞會識別IP位址的網路部分,而位址後綴會識別主機部分。 前置詞是由全域授權單位指派,後綴是由本機系統管理員指派。

這項列舉供 UnicastIPAddressInformation 類別使用。 當您擷取 物件的單播地址資訊時,會傳回這個類別的 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