英語で読む

次の方法で共有


NetworkInterface.GetAllNetworkInterfaces メソッド

定義

ローカル コンピューターのネットワーク インターフェイスを記述するオブジェクトを返します。

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("illumos")]
[System.Runtime.Versioning.UnsupportedOSPlatform("solaris")]
public static System.Net.NetworkInformation.NetworkInterface[] GetAllNetworkInterfaces();
C#
public static System.Net.NetworkInformation.NetworkInterface[] GetAllNetworkInterfaces();

戻り値

使用可能なネットワーク インターフェイスを記述するオブジェクトを格納している NetworkInterface 配列。インターフェイスが検出されない場合は、空の配列。

属性

例外

Windows システム関数の呼び出しが失敗しました。

次のコード例では、ローカル コンピューターのネットワーク アダプターのドメイン ネーム サービス (DNS) 構成情報を表示します。

C#
public static void DisplayDnsConfiguration()
{
    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties properties = adapter.GetIPProperties();
        Console.WriteLine(adapter.Description);
        Console.WriteLine("  DNS suffix .............................. : {0}",
            properties.DnsSuffix);
        Console.WriteLine("  DNS enabled ............................. : {0}",
            properties.IsDnsEnabled);
        Console.WriteLine("  Dynamically configured DNS .............. : {0}",
            properties.IsDynamicDnsEnabled);
    }
    Console.WriteLine();
}

注釈

コンピューター上のネットワーク インターフェイスは、ネットワーク接続を提供します。 ネットワーク インターフェイスは、ネットワーク アダプターとも呼ばれます。

適用対象

製品 バージョン
.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, 10
.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