NetworkInterface Class

Definition

Fornisce informazioni statistiche e di configurazione per un'interfaccia di rete.Provides configuration and statistical information for a network interface.

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
Inheritance
NetworkInterface

Examples

Nell'esempio di codice seguente vengono visualizzate informazioni sulle interfacce.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();
    }

Remarks

Questa classe incapsula i dati per le interfacce di rete, note anche come adapter, nel computer locale.This class encapsulates data for network interfaces, also known as adapters, on the local computer. Non è possibile creare istanze di questa classe. il metodo GetAllNetworkInterfaces restituisce una matrice che contiene un'istanza di questa classe per ogni interfaccia di rete nel computer locale.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.

Constructors

NetworkInterface()

Inizializza una nuova istanza della classe NetworkInterface.Initializes a new instance of the NetworkInterface class.

Properties

Description

Ottiene la descrizione dell'interfaccia.Gets the description of the interface.

Id

Ottiene l'identificatore della scheda di rete.Gets the identifier of the network adapter.

IPv6LoopbackInterfaceIndex

Ottiene l'indice dell'interfaccia di loopback IPv6.Gets the index of the IPv6 loopback interface.

IsReceiveOnly

Ottiene il valore Boolean che indica se l'interfaccia di rete è impostata in modo da ricevere solo pacchetti di dati.Gets a Boolean value that indicates whether the network interface is set to only receive data packets.

LoopbackInterfaceIndex

Ottiene l'indice dell'interfaccia di loopback IPv4.Gets the index of the IPv4 loopback interface.

Name

Ottiene il nome della scheda di rete.Gets the name of the network adapter.

NetworkInterfaceType

Ottiene il tipo di interfaccia.Gets the interface type.

OperationalStatus

Ottiene lo stato operativo corrente della connessione di rete.Gets the current operational state of the network connection.

Speed

Ottiene la velocità dell'interfaccia di rete.Gets the speed of the network interface.

SupportsMulticast

Ottiene il valore Boolean che indica se nell'interfaccia di rete è attivata la ricezione di pacchetti multicast.Gets a Boolean value that indicates whether the network interface is enabled to receive multicast packets.

Methods

GetAllNetworkInterfaces()

Restituisce oggetti che descrivono le interfacce di rete del computer locale.Returns objects that describe the network interfaces on the local computer.

GetIPProperties()

Restituisce un oggetto che descrive la configurazione di questa interfaccia di rete.Returns an object that describes the configuration of this network interface.

GetIPStatistics()

Ottiene le statistiche IP per questa istanza di NetworkInterface.Gets the IP statistics for this NetworkInterface instance.

GetIPv4Statistics()

Ottiene le statistiche IPv$ per questa istanza di NetworkInterface.Gets the IPv4 statistics for this NetworkInterface instance.

GetIsNetworkAvailable()

Indica se esiste una connessione di rete disponibile.Indicates whether any network connection is available.

GetPhysicalAddress()

Restituisce l'indirizzo Media Access Control (MAC) o fisico della scheda di rete.Returns the Media Access Control (MAC) or physical address for this adapter.

Supports(NetworkInterfaceComponent)

Ottiene un valore Boolean che indica se l'interfaccia supporta il protocollo specificato.Gets a Boolean value that indicates whether the interface supports the specified protocol.

Applies to