public void SelectNic() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { var interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (var nic in interfaces) { if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet || nic.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet || nic.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) { var entity = new NicsEntity { Name = nic.Name, Description = nic.Description }; _nicList.Add(entity); } } Console.WriteLine(); Console.WriteLine(Strings.Nic + " [0..n]:"); for (int i = 0; i < _nicList.Count; i++) { var nic = _nicList[i]; Console.WriteLine(i.ToString() + ": " + nic.Name + " (" + nic.Description + ")"); } bool selectionSuccessful = false; uint index = 0; while (!selectionSuccessful) { Console.WriteLine(); string selection = Console.ReadLine(); if (uint.TryParse(selection, out index)) { if (index < _nicList.Count) { selectionSuccessful = true; } } } _selectedNicIndex = (int)index; } }
private void SetNicList() { Nics.Clear(); var nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (var nic in nics) { if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet || nic.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet || nic.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) { var entity = new NicsEntity { Name = nic.Name, Description = nic.Description }; Nics.Add(entity); } } SelectedNicIndex = 0; }