NetworkInterface Class
.NET Framework 3.0
Provides configuration and statistical information for a network interface.
Namespace: System.Net.NetworkInformation
Assembly: System (in system.dll)
Assembly: System (in system.dll)
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.
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(); }
- SecurityPermission for executing unmanaged code. Associated enumeration: UnmanagedCode
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: