public static String IdToNetworkPrivatise(String AdapID) { var NLM = new NetworkListManager(); var NetList = NLM.GetNetworkConnections(); String ReturnMesg = " "; foreach (INetworkConnection NetIter in NetList) { if (NetIter.GetAdapterId().ToString().ToUpper() == AdapID.Trim().TrimEnd('}').TrimStart('{')) { ReturnMesg = NetIter.GetNetwork().GetName().ToString(); ReturnMesg += " : "; ReturnMesg += NetIter.GetNetwork().GetCategory().ToString(); // set network private NetIter.GetNetwork().SetCategory(NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE); // authorize this app to fw; fallback measure FirewallHelper.Instance.GrantAuthorization(Assembly.GetExecutingAssembly().Location, "xomanufacture", NET_FW_SCOPE_.NET_FW_SCOPE_ALL, NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY); // disable the fw in private profiles FirewallHelper.Instance.SetFirewallStatus(false); //Console.WriteLine(FirewallHelper.Instance.HasAuthorization(Assembly.GetExecutingAssembly().Location).ToString()); return(ReturnMesg); } } ReturnMesg = "No Network"; return(ReturnMesg); }
private void FillNetworkInfo(NetworkAdapter adapter) { //List the connected networks. There are many other APIs //can be called to get network information. try { IEnumNetworkConnections connections = NetworkListManager.GetNetworkConnections(); foreach (INetworkConnection con in connections) { var adapterId = con.GetAdapterId(); if (adapter.Id != adapterId) { continue; } //var connectionId = con.GetConnectionId(); adapter.ConnectivityString = GetConnectivity(con.GetConnectivity()); adapter.IsConnected = con.IsConnected; adapter.IsConnectedToInternet = con.IsConnectedToInternet; INetwork network = con.GetNetwork(); adapter.NetworkName = network.GetName(); // var networkCategory = network.GetCategory(); //var adapter = _networkAdapters.FirstOrDefault(x => x.Id == adapterId); } } catch (Exception ex) { Logging.Log("Error: " + ex.ToString()); } //AdviseforNetworklistManager(); // UnAdviseforNetworklistManager(); }
public void IsConnectedIsConsistentWithGetNetworkConnections() { bool isConnected = NetworkListManager.IsConnected; bool moreThanZeroConnections = false; foreach (NetworkConnection c in NetworkListManager.GetNetworkConnections()) { moreThanZeroConnections = true; break; } Assert.Equal(isConnected, moreThanZeroConnections); }
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); } }
// Retrieve available information for a given network id (nid) from the .NET NetworkListManager. private void GetNLMInfo(Guid nid, DataGridViewRow row) { INetwork nlm_net = null; foreach (INetworkConnection nc in nlm.GetNetworkConnections()) { if (nc.GetAdapterId().Equals(nid)) { nlm_net = nc.GetNetwork(); break; // foreach } } // If we didn't find any information, these fields in the grid // will just remain empty. if (nlm_net != null) { // Fill in the appropriate cells in the data grid based on // information from the NetworkListManager. row.Cells["NLA_Description"].Value = nlm_net.GetDescription(); switch (nlm_net.GetCategory()) { case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PUBLIC: row.Cells["NLA_Category"].Value = "Public"; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_PRIVATE: row.Cells["NLA_Category"].Value = "Private"; break; case NLM_NETWORK_CATEGORY.NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED: row.Cells["NLA_Category"].Value = "Domain"; break; } if (nlm_net.IsConnectedToInternet) { row.Cells["Internet"].Value = "Connected"; } } }