This topic has not yet been rated - Rate this topic

NetworkInterface.GetAllNetworkInterfaces Method

Returns objects that describe the network interfaces on the local computer.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)
public static NetworkInterface[] GetAllNetworkInterfaces()

Return Value

Type: System.Net.NetworkInformation.NetworkInterface[]
A NetworkInterface array that contains objects that describe the available network interfaces, or an empty array if no interfaces are detected.
Exception Condition
NetworkInformationException

A Windows system function call failed.

The network interfaces on a computer provide network connectivity. Network interfaces are also known as network adapters.

The following code example displays Domain Name Service (DNS) configuration information for the local computer's network adapters.


public static void DisplayDnsConfiguration()
{
    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties properties = adapter.GetIPProperties();
        Console.WriteLine(adapter.Description);
        Console.WriteLine("  DNS suffix .............................. : {0}",
            properties.DnsSuffix);
        Console.WriteLine("  DNS enabled ............................. : {0}", 
            properties.IsDnsEnabled);
        Console.WriteLine("  Dynamically configured DNS .............. : {0}", 
            properties.IsDynamicDnsEnabled);
    }
    Console.WriteLine();
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
GetAllNetworkInterfaces sample - rewritten in PowerShell
<#
.SYNOPSIS
This script shows the DNS Configuration of NICs
in your system
.DESCRIPTION
This script is a re-write of an MSDN Sample
using POwerSHell./ The sctipt gets all network
active network interfaces then prints out that
interfaces's DNS Properties.
.NOTES
File Name : Show-DnsConfiguration.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted to:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx
.EXAMPLE
Psh[C:\foo]> .\Show-DnsConfiguration.ps1
Broadcom NetXtreme 57xx Gigabit Controller
DNS suffix .............................. : cookham.net
DNS enabled ............................. : False
Dynamically configured DNS .............. : True

... more interfaces snipped for brevity!
#>

# Get the adapters than iterate over the collection and display DNS configuration
$adapters = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
ForEach ($adapter in $adapters) {
$properties = $adapter.GetIPProperties()
$adapter.Description
" DNS suffix .............................. : {0}" -f $properties.DnsSuffix
" DNS enabled ............................. : {0}" -f $properties.IsDnsEnabled
" Dynamically configured DNS .............. : {0}" -f $properties.IsDynamicDnsEnabled
}
Memory Leak ?
I think there is a memory leak in this method if it's used in a graphic process...

In my app I use this method in a connexion to server verification every minute.

And each minute the time to get all the network interface increase by 50-100ms and the memory usage by some octets..

by 13hours every minute the method use 40sec to get all the network interface... (and around 300Mo of RAM)
Disabled Adapter Not Listed
For the life of me, I cannot understand why disabled adapters would not be included in the list.   If I want to report device status I need to see both disabled and enabled devices.