NetworkInterface クラス

定義

ネットワーク インターフェイスの構成と統計情報を提供します。

public ref class NetworkInterface abstract sealed
public ref class NetworkInterface abstract
public static class NetworkInterface
public abstract class NetworkInterface
type NetworkInterface = class
Public Class NetworkInterface
Public MustInherit Class NetworkInterface
継承
NetworkInterface

次のコード例では、インターフェイスに関する情報を表示します。

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();
        Console.WriteLine();
        Console.WriteLine(adapter.Description);
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
        Console.WriteLine("  Interface type .......................... : {0}", adapter.NetworkInterfaceType);
        Console.WriteLine("  Physical Address ........................ : {0}",
                   adapter.GetPhysicalAddress().ToString());
        Console.WriteLine("  Operational status ...................... : {0}",
            adapter.OperationalStatus);
        string versions ="";

        // Create a display string for the supported IP versions.
        if (adapter.Supports(NetworkInterfaceComponent.IPv4))
        {
             versions = "IPv4";
         }
        if (adapter.Supports(NetworkInterfaceComponent.IPv6))
        {
            if (versions.Length > 0)
            {
                versions += " ";
             }
            versions += "IPv6";
        }
        Console.WriteLine("  IP version .............................. : {0}", versions);
        ShowIPAddresses(properties);

        // The following information is not useful for loopback adapters.
        if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
        {
            continue;
        }
        Console.WriteLine("  DNS suffix .............................. : {0}",
            properties.DnsSuffix);

        string label;
        if (adapter.Supports(NetworkInterfaceComponent.IPv4))
        {
            IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();
            Console.WriteLine("  MTU...................................... : {0}", ipv4.Mtu);
            if (ipv4.UsesWins)
            {

                IPAddressCollection winsServers = properties.WinsServersAddresses;
                if (winsServers.Count > 0)
                {
                    label = "  WINS Servers ............................ :";
                    ShowIPAddresses(label, winsServers);
                }
            }
        }

        Console.WriteLine("  DNS enabled ............................. : {0}",
            properties.IsDnsEnabled);
        Console.WriteLine("  Dynamically configured DNS .............. : {0}",
            properties.IsDynamicDnsEnabled);
        Console.WriteLine("  Receive Only ............................ : {0}",
            adapter.IsReceiveOnly);
        Console.WriteLine("  Multicast ............................... : {0}",
            adapter.SupportsMulticast);
        ShowInterfaceStatistics(adapter);

        Console.WriteLine();
    }
}

注釈

このクラスは、ローカル コンピューター上のネットワーク インターフェイス (アダプターとも呼ばれます) のデータをカプセル化します。 このクラスのインスタンスは作成しません。 GetAllNetworkInterfaces メソッドは、ローカル コンピューター上のネットワーク インターフェイスごとに、このクラスの 1 つのインスタンスを含む配列を返します。

コンストラクター

名前 説明
NetworkInterface()

NetworkInterface クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Description

インターフェイスの説明を取得します。

Id

ネットワーク アダプターの識別子を取得します。

IPv6LoopbackInterfaceIndex

IPv6 ループバック インターフェイスのインデックスを取得します。

IsReceiveOnly

ネットワーク インターフェイスがデータ パケットのみを受信するように設定されているかどうかを示す Boolean 値を取得します。

LoopbackInterfaceIndex

IPv4 ループバック インターフェイスのインデックスを取得します。

Name

ネットワーク アダプターの名前を取得します。

NetworkInterfaceType

インターフェイスの種類を取得します。

OperationalStatus

ネットワーク接続の現在の操作状態を取得します。

Speed

ネットワーク インターフェイスの速度を取得します。

SupportsMulticast

ネットワーク インターフェイスがマルチキャスト パケットの受信を有効にするかどうかを示す Boolean 値を取得します。

メソッド

名前 説明
GetAllNetworkInterfaces()

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

GetIPProperties()

このネットワーク インターフェイスの構成を記述するオブジェクトを返します。

GetIPStatistics()

この NetworkInterface インスタンスの IP 統計情報を取得します。

GetIPv4Statistics()

この NetworkInterface インスタンスの IPv4 統計を取得します。

GetIsNetworkAvailable()

ネットワーク接続が使用可能かどうかを示します。

GetPhysicalAddress()

このアダプターのメディア Access Control (MAC) または物理アドレスを返します。

Supports(NetworkInterfaceComponent)

インターフェイスが指定したプロトコルをサポートしているかどうかを示す Boolean 値を取得します。

適用対象