/// <summary> /// Get the Adapter ID from the supplied network ID /// </summary> /// <param name="vNetworkID"></param> /// <param name="vConnectivityLevels"></param> /// <returns></returns> public static Guid getAdapterID(string vNetworkID, NetworkConnectivityLevels vConnectivityLevels) { Guid output = new Guid(); NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivityLevels); foreach (Network n in netCollection) { string nID = n.NetworkId.ToString(); //if (nID.Equals(vNetworkID.ToString().ToUpper())) if (nID == vNetworkID.ToString()) { foreach (NetworkConnection c in n.Connections) { if (c.Network.NetworkId == n.NetworkId) { output = c.AdapterId; break; } } } } return(output); }
/* Lists connected networks by profile */ public List <string> NetworksByProfileList(NET_FW_PROFILE_TYPE2_ profile, NetworkConnectivityLevels level = NetworkConnectivityLevels.All) { List <string> networks = new List <string>(); NetworkCategory profileName = NetworkCategory.Public; switch (profile) { case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN: profileName = NetworkCategory.Authenticated; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE: profileName = NetworkCategory.Private; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC: profileName = NetworkCategory.Public; break; } //Install-Package WindowsAPICodePack-Core NetworkCollection nCollection = NetworkListManager.GetNetworks(level); foreach (Network net in nCollection) { if (net.Category == profileName) { networks.Add(net.Name); } } return(networks); }
/// <summary> /// Retrieves a collection of <see cref="Network"/> objects that represent the networks defined for this machine. /// </summary> /// <param name="level"> /// The <see cref="NetworkConnectivityLevels"/> that specify the connectivity level of the returned <see cref="Network"/> objects. /// </param> /// <returns> /// A <see cref="NetworkCollection"/> of <see cref="Network"/> objects. /// </returns> public static NetworkCollection GetNetworks(NetworkConnectivityLevels level) { // Throw PlatformNotSupportedException if the user is not running Vista or beyond //CoreHelpers.ThrowIfNotVista(); return(new NetworkCollection(manager.GetNetworks(level))); }
/// <summary> /// Retrieves a collection of <see cref="Network"/> objects that represent the networks defined for this machine. /// </summary> /// <param name="level"> /// The <see cref="NetworkConnectivityLevels"/> that specify the connectivity level of the returned <see cref="Network"/> objects. /// </param> /// <returns> /// A <see cref="NetworkCollection"/> of <see cref="Network"/> objects. /// </returns> public static NetworkCollection GetNetworks(NetworkConnectivityLevels level) { // Throw PlatformNotSupportedException if the user is not running Vista or beyond CoreHelpers.ThrowIfNotVista(); return new NetworkCollection(manager.GetNetworks(level)); }
/// <summary> /// fill the network combo box list with a custom combo box item /// </summary> /// <param name="vSelectedNetworkName"></param> /// <param name="vConnectivity"></param> private void FillNetworkList(string vSelectedNetworkName, NetworkConnectivityLevels vConnectivity) { cbNetwork.Items.Clear(); NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivity); // NetworkConnectivityLevels.Connected); ComboboxItemCustom comboItem; var orderedList = netCollection.OrderBy(x => x.Name); //.ThenByDescending(x => x.Name); foreach (Network n in orderedList) { { comboItem = new ComboboxItemCustom(n.Name, n.NetworkId.ToString(), n.IsConnectedToInternet); cbNetwork.Items.Add(comboItem); if (vSelectedNetworkName == n.Name) { cbNetwork.SelectedItem = comboItem; } } } if (String.IsNullOrEmpty(vSelectedNetworkName)) { cbNetwork.Text = "(Select One)"; } }
/// <summary> /// Get the information on if the network is connected, and connected to the internet /// </summary> /// <param name="vNetworkName"></param> /// <param name="vConnectivityLevels"></param> /// <param name="vIsConnected"></param> /// <param name="vIsConnectedToInternet"></param> public static void getNetworkConnectionInfo(String vNetworkName, NetworkConnectivityLevels vConnectivityLevels, out bool vIsConnected, out bool vIsConnectedToInternet) { vIsConnected = false; vIsConnectedToInternet = false; NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivityLevels); foreach (Network n in netCollection) { if (n.Name == vNetworkName) { vIsConnected = n.IsConnected; vIsConnectedToInternet = n.IsConnectedToInternet; break; } } }
/// <summary> /// Get the ID for the network from the name/ssid /// </summary> /// <param name="vNetworkName"></param> /// <param name="vConnectivityLevels"></param> /// <returns></returns> public static Guid getNetworkID(String vNetworkName, NetworkConnectivityLevels vConnectivityLevels) { Guid output = new Guid(); NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivityLevels); foreach (Network n in netCollection) { if (n.Name == vNetworkName) { output = n.NetworkId; break; } } return(output); }
/// <summary> /// Get the network name from the ID /// </summary> /// <param name="vNetworkId"></param> /// <param name="vConnectivityLevels"></param> /// <returns></returns> public static string getNetworkName(Guid vNetworkId, NetworkConnectivityLevels vConnectivityLevels) { string output = string.Empty; NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivityLevels); foreach (Network n in netCollection) { if (n.NetworkId == vNetworkId) { output = n.Name; break; } } return(output); }
/// <summary> /// Get the Connection ID for the supplied network /// </summary> /// <param name="vNetworkID"></param> /// <param name="vConnectivityLevels"></param> /// <returns></returns> public static Guid getConnectionID(Guid vNetworkID, NetworkConnectivityLevels vConnectivityLevels) { Guid output = new Guid(); NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivityLevels); foreach (Network n in netCollection) { foreach (NetworkConnection c in n.Connections) { if (c.Network.NetworkId == n.NetworkId && vNetworkID == c.Network.NetworkId) { output = c.ConnectionId; break; } } } return(output); }
/// <summary> /// Retrieves a collection of <see cref="Microsoft.SDK.Samples.VistaBridge.Library.Network.Network"/> objects that represent the networks defined for this machine. /// </summary> /// <param name="level"> /// The <see cref="Microsoft.SDK.Samples.VistaBridge.Library.Network.NetworkConnectivityLevels"/> that specify the connectivity level of the returned <see cref="Microsoft.SDK.Samples.VistaBridge.Library.Network.Network"/> objects. /// </param> /// <returns> /// A <see cref="Microsoft.SDK.Samples.VistaBridge.Library.Network.NetworkCollection"/> of <see cref="Microsoft.SDK.Samples.VistaBridge.Library.Network.Network"/> objects. /// </returns> public static NetworkCollection GetNetworks(NetworkConnectivityLevels level) { return new NetworkCollection(manager.GetNetworks(level)); }
public virtual extern IEnumerable GetNetworks([In] NetworkConnectivityLevels Flags);
public static NetworkCollection GetNetworks(NetworkConnectivityLevels level) { return(new NetworkCollection(manager.GetNetworks(level))); }
public Dictionary <string, List <string> > NetworksByProfileDict(NET_FW_PROFILE_TYPE2_ profile, NetworkConnectivityLevels level = NetworkConnectivityLevels.All) { var networks = new Dictionary <string, List <string> >(); //populate interface lookup var adapterLookup = new Dictionary <string, string>(); NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { //from:{E46DFF2D-EB92-4A84-A0D3-01DDD2DC041E} // to: e46dff2d-eb92-4a84-a0d3-01ddd2dc041e logger.Debug("Adapter: {0}={1}", adapter.Id.ToLower().Replace("{", "").Replace("}", ""), adapter.Name); adapterLookup.Add(adapter.Id.ToLower().Replace("{", "").Replace("}", ""), adapter.Name); } NetworkCategory profileName = NetworkCategory.Public; switch (profile) { case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN: profileName = NetworkCategory.Authenticated; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE: profileName = NetworkCategory.Private; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC: profileName = NetworkCategory.Public; break; } /* * NetworkCollection nCollection2 = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); * foreach (Network net in nCollection2) * { * if (net.IsConnected || net.IsConnectedToInternet) * { * Console.WriteLine(String.Format("CONNECTED: {0} {1} {2} {3}", net.Name, net.Category, net.DomainType, net.IsConnectedToInternet)); * } * else * { * Console.WriteLine(String.Format("Not connected: {0} {1} {2} {3}", net.Name, net.Category, net.DomainType, net.IsConnectedToInternet)); * } * } */ //Install-Package WindowsAPICodePack-Core NetworkCollection nCollection = NetworkListManager.GetNetworks(level); foreach (Network net in nCollection) { logger.Debug("Network: {0}={1}", net.Name, net.Category); if (net.Category == profileName) { var netAdapters = new List <string>(); var conns = net.Connections; if (conns.Count() == 0) { logger.Debug("No active connections for network"); } foreach (var c in conns) { if (adapterLookup.ContainsKey(c.AdapterId.ToString())) { logger.Debug("Found adapter: {0}", adapterLookup[c.AdapterId.ToString()]); netAdapters.Add(adapterLookup[c.AdapterId.ToString()]); } else { logger.Debug("Unknown adapter: {0}", c.AdapterId.ToString()); netAdapters.Add("Unknown"); } } networks.Add(net.Name, new List <string>()); foreach (var na in netAdapters) { networks[net.Name].Add(na); } } } return(networks); }
internal static IEnumerable <NetworkInfo> EnumerateNetworksCore(Guid?networkID, NetworkConnectivityLevels networkConnectivityLevels) { if (null != networkID) { yield return(new NetworkInfo(Manager.GetNetwork((Guid)networkID))); } else { foreach (INetwork network in Manager.GetNetworks(networkConnectivityLevels)) { yield return(new NetworkInfo(network)); } } }
public static IEnumerable <NetworkInfo> EnumerateNetworks(NetworkConnectivityLevels networkConnectivityLevels) { return(EnumerateNetworksCore(null, networkConnectivityLevels)); }
public extern IEnumerable GetNetworks([In] NetworkConnectivityLevels flags);