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

예제

다음 코드 예제에서는 인터페이스에 대한 정보를 표시합니다.

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 로컬 컴퓨터의 각 네트워크 인터페이스에 대해 이 클래스의 인스턴스를 하나 포함하는 배열을 반환합니다.

생성자

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

이 어댑터에 대한 MAC(Media Access Control) 또는 실제 주소를 반환합니다.

Supports(NetworkInterfaceComponent)

인터페이스가 지정된 프로토콜을 지원하는지 여부를 나타내는 Boolean 값을 가져옵니다.

적용 대상