Exemple #1
0
 // Enable/Disable Outer Netowrk
 private void outerNetworkButton_Click(object sender, EventArgs e)
 {
     NetworkAdapter.enableNetworkAdapter(NetworkAdapter.OuterAdapterIndex, !NetworkAdapter.OuterAdapterEnabled);
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="netAdapList"></param>
        private void setNetworkAdapterInfo()
        {
            string output = CommandLine.getCommandOutput("nic get name, index, NetConnectionID, netenabled", "wmic.exe");

            //splited wmic output with NEW_LINE to get array
            string[] fullLine = output.Split(new string[] { "\n" }, StringSplitOptions.None);

            int c = -1;

            //normalizing wmic output by removing unneeded characters
            for (int i = 0; i <= fullLine.Length - 1; i++)
            {
                c++;

                while (fullLine[i].Contains("\r"))
                {
                    fullLine[i] = fullLine[i].Replace("\r", "");
                }
                ;

                if (fullLine[i].Contains("  "))
                {
                    do
                    {
                        fullLine[i] = fullLine[i].Replace("   ", "  ");
                    } while (fullLine[i].Contains("   "));
                }
            }

            //setting array
            string[][] splitedNetworkArray = new string[c][];

            for (int i = 1; i < fullLine.Length; i++)
            {
                int idx = i - 1;
                // avoiding 1st row wich contains column names
                splitedNetworkArray[idx] = fullLine[i].Trim().Split(new string[] { "  " }, StringSplitOptions.None);
                if (splitedNetworkArray[idx].Length == 4)
                {
                    NetworkAdapter na = new NetworkAdapter(int.Parse(splitedNetworkArray[idx][0]), splitedNetworkArray[idx][1], splitedNetworkArray[idx][2], bool.Parse(splitedNetworkArray[idx][3]));

                    if (netAdapterList.Contains(na))
                    {
                        int            index = netAdapterList.IndexOf(na);
                        NetworkAdapter na2   = netAdapterList.ElementAt(index);
                        na2.NetEnabled = na.NetEnabled;
                    }
                    else
                    {
                        netAdapterList.Add(na);
                    }
                }

                if (splitedNetworkArray[idx].Length == 2 && !checkBoxHideVirtualAdapter.Checked)
                {
                    NetworkAdapter na = new NetworkAdapter(int.Parse(splitedNetworkArray[idx][0]), splitedNetworkArray[idx][1], null, false);

                    if (netAdapterList.Contains(na))
                    {
                        int            index = netAdapterList.IndexOf(na);
                        NetworkAdapter na2   = netAdapterList.ElementAt(index);
                        na2.NetEnabled = na.NetEnabled;
                    }
                    else
                    {
                        netAdapterList.Add(na);
                    }
                }
            }
        }