public static AdaptorNetworkInfo GetAdaptorNetworkInfo(string nameOrDesc) { Logger.Info("GetAdaptorNetworkInfo for " + nameOrDesc); var physicalNics = GetAllActiveLocalPhysicalNics(); foreach (var networkInterface in physicalNics) { if (networkInterface.Description.Equals(nameOrDesc) || networkInterface.Name.Equals(nameOrDesc)) { var adaptorDescriptionOrName = networkInterface.Description; var adaptorNetworkInfo = new AdaptorNetworkInfo { Description = adaptorDescriptionOrName, IpAddress = GetAdapterIp4Address(adaptorDescriptionOrName), Gateway = NetworkManagement.GetGatewayForAdaptor(adaptorDescriptionOrName), IsDhcpEnabled = !NetworkManagement.IsNetworkedWithStaticIp(adaptorDescriptionOrName), Name = networkInterface.Name }; Logger.Info("GetAdaptorNetworkInfo Found Match " + adaptorNetworkInfo); return(adaptorNetworkInfo); } } return(new AdaptorNetworkInfo()); }
public static void ShowNetworkInterfaces(bool onlyPhysicalAdaptors = true, bool verbose = false) { var idx = 1; var computerProperties = IPGlobalProperties.GetIPGlobalProperties(); var nics = onlyPhysicalAdaptors ? GetAllActiveLocalPhysicalNics() : NetworkInterface.GetAllNetworkInterfaces().ToList(); Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName); if (nics == null || nics.Count < 1) { Console.WriteLine(" No network interfaces found."); return; } Console.WriteLine(" Number of interfaces .................... : {0}", nics.Count); foreach (var adapter in nics) { var properties = adapter.GetIPProperties(); Console.WriteLine(); Console.WriteLine(idx++ + ". " + 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); Console.WriteLine(" IP4 Address ............................. : {0}", GetIpFromAdaptorDesc(adapter.Description)); Console.WriteLine(" IP4 Subnet Mask ..........................: {0}", GetIp4MaskFromAdaptorDesc(adapter.Description)); Console.WriteLine(" Default Gateway ..........................: {0}", NetworkManagement.GetGatewayForAdaptor(adapter.Description)); var 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); if (verbose) { 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)) { var ipv4 = properties.GetIPv4Properties(); Console.WriteLine(" MTU...................................... : {0}", ipv4.Mtu); if (ipv4.UsesWins) { var 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(); } }