NetworkInterface NetworkInterface NetworkInterface NetworkInterface Class

Definition

Stellt Konfigurations- und Statistikinformationen für eine Netzwerkschnittstelle bereit.Provides configuration and statistical information for a network interface.

public ref class NetworkInterface abstract
public abstract class NetworkInterface
type NetworkInterface = class
Public MustInherit Class NetworkInterface
Vererbung
NetworkInterfaceNetworkInterfaceNetworkInterfaceNetworkInterface

Beispiele

Das folgende Codebeispiel zeigt Informationen zu den Schnittstellen.The following code example displays information about interfaces.

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

Hinweise

Diese Klasse kapselt Daten für die Netzwerkschnittstellen, auch bekannt als Adapter aus, auf dem lokalen Computer.This class encapsulates data for network interfaces, also known as adapters, on the local computer. Erstellen Sie Instanzen dieser Klasse nicht. die GetAllNetworkInterfaces Methode gibt ein Array, das eine Instanz dieser Klasse für jede Netzwerkschnittstelle auf dem lokalen Computer enthält.You do not create instances of this class; the GetAllNetworkInterfaces method returns an array that contains one instance of this class for each network interface on the local computer.

Konstruktoren

NetworkInterface() NetworkInterface() NetworkInterface() NetworkInterface()

Initialisiert eine neue Instanz der NetworkInterface-Klasse.Initializes a new instance of the NetworkInterface class.

Eigenschaften

Description Description Description Description

Ruft die Beschreibung der Schnittstelle ab.Gets the description of the interface.

Id Id Id Id

Ruft den Bezeichner der Netzwerkkarte ab.Gets the identifier of the network adapter.

IPv6LoopbackInterfaceIndex IPv6LoopbackInterfaceIndex IPv6LoopbackInterfaceIndex IPv6LoopbackInterfaceIndex

Ruft den Index der IPv6-Loopbackschnittstelle ab.Gets the index of the IPv6 loopback interface.

IsReceiveOnly IsReceiveOnly IsReceiveOnly IsReceiveOnly

Ruft einen Boolean-Wert ab, der angibt, ob die Netzwerkschnittstelle zum Empfangen von Datenpaketen festgelegt ist.Gets a Boolean value that indicates whether the network interface is set to only receive data packets.

LoopbackInterfaceIndex LoopbackInterfaceIndex LoopbackInterfaceIndex LoopbackInterfaceIndex

Ruft den Index der IPv4-Loopbackschnittstelle ab.Gets the index of the IPv4 loopback interface.

Name Name Name Name

Ruft den Namen der Netzwerkkarte ab.Gets the name of the network adapter.

NetworkInterfaceType NetworkInterfaceType NetworkInterfaceType NetworkInterfaceType

Ruft den Schnittstellentyp ab.Gets the interface type.

OperationalStatus OperationalStatus OperationalStatus OperationalStatus

Ruft den aktuellen Betriebszustand der Netzwerkverbindung ab.Gets the current operational state of the network connection.

Speed Speed Speed Speed

Ruft die Geschwindigkeit der Netzwerkschnittstelle ab.Gets the speed of the network interface.

SupportsMulticast SupportsMulticast SupportsMulticast SupportsMulticast

Ruft einen Boolean-Wert ab, der angibt, ob die Netzwerkschnittstelle für den Empfang von Multicastpaketen aktiviert ist.Gets a Boolean value that indicates whether the network interface is enabled to receive multicast packets.

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAllNetworkInterfaces() GetAllNetworkInterfaces() GetAllNetworkInterfaces() GetAllNetworkInterfaces()

Gibt Objekte zurück, die die Netzwerkschnittstellen auf dem lokalen Computer beschreiben.Returns objects that describe the network interfaces on the local computer.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetIPProperties() GetIPProperties() GetIPProperties() GetIPProperties()

Gibt ein Objekt zurück, das die Konfiguration dieser Netzwerkschnittstelle beschreibt.Returns an object that describes the configuration of this network interface.

GetIPStatistics() GetIPStatistics() GetIPStatistics() GetIPStatistics()

Ruft die IP-Statistik für diese NetworkInterface-Instanz ab.Gets the IP statistics for this NetworkInterface instance.

GetIPv4Statistics() GetIPv4Statistics() GetIPv4Statistics() GetIPv4Statistics()

Ruft die IPv4-Statistik für diese NetworkInterface-Instanz ab.Gets the IPv4 statistics for this NetworkInterface instance.

GetIsNetworkAvailable() GetIsNetworkAvailable() GetIsNetworkAvailable() GetIsNetworkAvailable()

Gibt an, ob eine Netzwerkverbindung verfügbar ist.Indicates whether any network connection is available.

GetPhysicalAddress() GetPhysicalAddress() GetPhysicalAddress() GetPhysicalAddress()

Gibt die MAC (Media Access Control)-Adresse oder physische Adresse für diesen Adapter zurück.Returns the Media Access Control (MAC) or physical address for this adapter.

GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
Supports(NetworkInterfaceComponent) Supports(NetworkInterfaceComponent) Supports(NetworkInterfaceComponent) Supports(NetworkInterfaceComponent)

Ruft einen Boolean-Wert ab, der angibt, ob die Schnittstelle das angegebene Protokoll unterstützt.Gets a Boolean value that indicates whether the interface supports the specified protocol.

ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Sicherheit

SecurityPermission
zum Ausführen von nicht verwalteten Codes.for executing unmanaged code. Zugeordnete Enumeration: UnmanagedCodeAssociated enumeration: UnmanagedCode

Gilt für: