NetworkInterface クラス
この記事の内容
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ネットワーク インターフェイスの構成および統計情報を提供します。
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
例
次のコード例では、インターフェイスに関する情報を表示します。
void ShowNetworkInterfaces()
{
IPGlobalProperties ^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
Console::WriteLine( "Interface information for {0}.{1} ", computerProperties->HostName, computerProperties->DomainName );
if ( nics == nullptr || nics->Length < 1 )
{
Console::WriteLine( " No network interfaces found." );
return;
}
Console::WriteLine( " Number of interfaces .................... : {0}", nics->Length );
System::Collections::IEnumerator^ myEnum4 = nics->GetEnumerator();
while ( myEnum4->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum4->Current);
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() );
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 = String::Concat( versions, " " );
}
versions = String::Concat( 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();
}
}
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 つのインスタンスを含む配列を返します。
コンストラクター
Network |
NetworkInterface クラスの新しいインスタンスを初期化します。 |
プロパティ
Description |
インターフェイスの説明を取得します。 |
Id |
ネットワーク アダプターの ID を取得します。 |
IPv6Loopback |
IPv6 ループバック インターフェイスのインデックスを取得します。 |
Is |
ネットワーク インターフェイスが、データ パケットの受信だけを行うように設定されているかどうかを示す Boolean 値を取得します。 |
Loopback |
IPv4 ループバック インターフェイスのインデックスを取得します。 |
Name |
ネットワーク アダプターの名前を取得します。 |
Network |
インターフェイスの種類を取得します。 |
Operational |
ネットワーク接続の現在の操作状態を取得します。 |
Speed |
ネットワーク インターフェイスの速度を取得します。 |
Supports |
ネットワーク インターフェイスでマルチキャスト パケットの受信が有効になっているかどうかを示す Boolean 値を取得します。 |
メソッド
Get |
ローカル コンピューターのネットワーク インターフェイスを記述するオブジェクトを返します。 |
Get |
このネットワーク インターフェイスの構成を記述するオブジェクトを返します。 |
Get |
この NetworkInterface インスタンスの IP 統計情報を取得します。 |
Get |
この NetworkInterface インスタンスの IPv4 の統計情報を取得します。 |
Get |
任意のネットワーク接続が使用できるかどうかを示します。 |
Get |
このアダプターのメディア アクセス制御 (MAC) アドレスまたは物理アドレスを返します。 |
Supports(Network |
指定したプロトコルをインターフェイスがサポートしているかどうかを示す Boolean 値を取得します。 |
適用対象
製品 | バージョン |
---|---|
.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 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。