/// <summary> /// Gets IP interfaces which are up /// </summary> private void GetInterfaces() { foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces()) { if (networkInterface.OperationalStatus == OperationalStatus.Up) { foreach (UnicastIPAddressInformation ip in networkInterface.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == AddressFamily.InterNetwork) { InterfaceList.Add(new IPNetworkInterface { InterfaceAddress = ip.Address.ToString(), InterfaceName = networkInterface.Name }); } } } } if (InterfaceList.Count > 0) { SelectedInterface = InterfaceList[0]; } else { selectedInterface = null; } RaisePropertyChanged("SelectedInterface"); }
private void RefreshInterfaceListExecute() { IPNetworkInterface prevSelectedAddress = SelectedInterface; InterfaceList.Clear(); GetInterfaces(); if (InterfaceList.Contains(prevSelectedAddress)) { SelectedInterface = prevSelectedAddress; } else if (InterfaceList.Count > 0) { SelectedInterface = InterfaceList[0]; } else { SelectedInterface = null; } RaisePropertyChanged("SelectedInterface"); }