英語で読む

次の方法で共有


SuffixOrigin 列挙型

定義

IP アドレスのホスト サフィックスが配置された方法を示します。

C#
public enum SuffixOrigin
継承
SuffixOrigin

フィールド

名前 説明
LinkLayerAddress 4

サフィックスは、リンクローカル サフィックスです。

Manual 1

サフィックスは、手動で構成されました。

OriginDhcp 3

サフィックスは、DHCP (Dynamic Host Configuration Protocol) サーバーによって提供されました。

Other 0

サフィックスは、未指定のソースを使用して配置されました。

Random 5

サフィックスは、ランダムに割り当てられました。

WellKnown 2

サフィックスは、既知のサフィックスです。 既知のサフィックスは、RFC (Request for Comments) のドキュメントの標準トラックで指定されていて、IANA (Internet Assigned Numbers Authority) またはアドレス レジストリによって割り当てられます。 このようなサフィックスは、特別な目的のために予約されています。

次のコード例では、ユニキャスト アドレスのプレフィックスとサフィックスの情報を表示します。

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 アドレスは、プレフィックスとサフィックスの 2 つの部分に分かれています。 アドレス プレフィックスは 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