public string Get(NetworkConnectionCollection networkConnections) { var current = Current(networkConnections); if (current != null) { return(string.Join(",", current.GetIPProperties().DnsAddresses?.Select(s => s.ToString()))); } return(string.Empty); }
private void LoadNetworkConnections() { NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); foreach (Network n in networks) { // Create a tab TabItem tabItem = new TabItem(); tabItem.Header = string.Format("Network {0} ({1})", tabControl1.Items.Count, n.Name); tabControl1.Items.Add(tabItem); // StackPanel stackPanel2 = new StackPanel(); stackPanel2.Orientation = Orientation.Vertical; // List all the properties AddProperty("Name: ", n.Name, stackPanel2); AddProperty("Description: ", n.Description, stackPanel2); AddProperty("Domain type: ", n.DomainType.ToString(), stackPanel2); AddProperty("Is connected: ", n.IsConnected.ToString(), stackPanel2); AddProperty("Is connected to the internet: ", n.IsConnectedToInternet.ToString(), stackPanel2); AddProperty("Network ID: ", n.NetworkId.ToString(), stackPanel2); AddProperty("Category: ", n.Category.ToString(), stackPanel2); AddProperty("Created time: ", n.CreatedTime.ToString(), stackPanel2); AddProperty("Connected time: ", n.ConnectedTime.ToString(), stackPanel2); AddProperty("Connectivity: ", n.Connectivity.ToString(), stackPanel2); // StringBuilder s = new StringBuilder(); s.AppendLine("Network Connections:"); NetworkConnectionCollection connections = n.Connections; foreach (NetworkConnection nc in connections) { s.AppendFormat("\n\tConnection ID: {0}\n\tDomain: {1}\n\tIs connected: {2}\n\tIs connected to internet: {3}\n", nc.ConnectionId, nc.DomainType, nc.IsConnected, nc.IsConnectedToInternet); s.AppendFormat("\tAdapter ID: {0}\n\tConnectivity: {1}\n", nc.AdapterId, nc.Connectivity); } s.AppendLine(); Label label = new Label(); label.Content = s.ToString(); stackPanel2.Children.Add(label); tabItem.Content = stackPanel2; } }
public void NetworkCollectionContainsAllNetworkConnections() { bool isConnected = NetworkListManager.IsConnected; ConnectivityStates connectivity = NetworkListManager.Connectivity; bool isConnectedToInternet = NetworkListManager.IsConnectedToInternet; NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); NetworkConnectionCollection connections = NetworkListManager.GetNetworkConnections(); // BUG: Both GetNetworks and GetNetworkConnections create new network objects, so // you can't do a reference comparison. // By inspection, the connections are contained in the NetworkCollection, just a different instance. foreach (NetworkConnection c in connections) { Assert.Contains(c.Network, networks); } }
/// <summary> /// Enumerator constructor /// </summary> public ConnectionEnumerator(NetworkConnectionCollection conMappings) { iEnLocal = conMappings; iEnBase = iEnLocal.GetEnumerator(); }
public NetworkInterface Current(NetworkConnectionCollection networkConnections) { return(NetworkInterfaces.SingleOrDefault(item => networkConnections.Select(s => s.AdapterId).Contains(Guid.Parse(item.Id)))); }