This documentation is archived and is not being maintained.

NetworkInterface Class

Provides configuration and statistical information for a network interface.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

'Declaration
Public MustInherit Class NetworkInterface
'Usage
Dim instance As NetworkInterface

This class encapsulates data for network interfaces, also known as adapters, on the local computer. 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.

The following code example displays information about interfaces.

No code example is currently available or this language may not be supported.
void ShowNetworkInterfaces()
{
    IPGlobalProperties* computerProperties = IPGlobalProperties::GetIPGlobalProperties();
    NetworkInterface* nics[] = NetworkInterface::GetAllNetworkInterfaces();
    Console::WriteLine(S"Interface information for {0}.{1}     ",
        computerProperties->HostName, computerProperties->DomainName);
    if (nics == 0 || nics->Length < 1)
    {
        Console::WriteLine(S"  No network interfaces found.");
        return;
    }

    Console::WriteLine(S"  Number of interfaces .................... : {0}", __box(nics->Length));
    System::Collections::IEnumerator* myEnum4 = nics->GetEnumerator();
    while (myEnum4->MoveNext())
    {
        NetworkInterface* adapter = __try_cast<NetworkInterface*>(myEnum4->Current);
        IPInterfaceProperties* properties = adapter->GetIPInterfaceProperties();
        Console::WriteLine();
        Console::WriteLine(adapter->Description);
        Console::WriteLine(String::Empty->PadLeft(adapter->Description->Length,'='));
        Console::WriteLine(S"  Interface type .......................... : {0}", __box(adapter->Type));
        Console::WriteLine(S"  Physical Address ........................ : {0}", 
            adapter->GetPhysicalAddress());
        Console::WriteLine(S"  Operational status ...................... : {0}", __box(adapter->OperationalStatus));
        String* versions =S"";

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

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

        String* label;
        if (adapter->Supports(NetworkInterfaceComponent::IPv4))
        {
            IPv4InterfaceProperties* ipv4 = properties->GetIPv4InterfaceProperties();
            Console::WriteLine(S"  MTU...................................... : {0}", __box(ipv4->Mtu));
            if (ipv4->UsesWins)
            {

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

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

        Console::WriteLine();
    }

System.Object
  System.Net.NetworkInformation.NetworkInterface

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: