public ApplicationForm()
        {
            InitializeComponent();
            SendMessage(this.buttonInstall.Handle, BCM_SETSHIELD, 0, 1);

            //Pull hardware information for all NICs
            ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");

            foreach (ManagementObject service in s.Get())
            {
                this.hardwareInfo[service.Properties["Name"].Value.ToString()] = service;
            }

            //Fetch the NIC information once
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                //Skip over adapters that aren't connected to a network
                if (adapter.OperationalStatus != OperationalStatus.Up)
                {
                    continue;
                }

                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                List <string>         dnsServers        = new List <string>();  //More accurate than IPInterfaceProperties.DnsAddresses
                List <string>         dnsServersv6      = new List <string>();

                //Determine if the DNS addresses are obtained automatically or specified
                //We don't want to add them when the program is closed if they weren't actually set
                //Unfortunately, neither WMI nor the NetworkInterface class provide information about this setting
                dnsServers   = NetworkManager.getDNS(adapter.Id);
                dnsServersv6 = NetworkManager.getDNSv6(adapter.Id);

                NetworkListItem item = new NetworkListItem(adapter.Name, adapter.Description, dnsServers, dnsServersv6, adapter.Supports(NetworkInterfaceComponent.IPv4), adapter.Supports(NetworkInterfaceComponent.IPv6), this.shouldHide(adapter));
                NICitems.Add(adapter.Name, new Pair <NetworkListItem, bool>(item, false));
            }

            GetNICs(false);

            // Start thread to monitor process/service status
            this.ServiceCheck = new Thread(new ThreadStart(this.update_Service_Info));
            this.ServiceCheck.Start();

            LoadPlugins();

            this.combobox_provider.DataSource    = Providers;
            this.combobox_provider.DisplayMember = "displayName";
            LoadConfig();
        }
        /// <summary>
        /// Fills the ListBox with information about each NIC
        /// </summary>
        private void GetNICs()
        {
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                List<string> dnsServers = new List<string>();	//More accurate than IPInterfaceProperties.DnsAddresses

                //Determine if the DNS addresses are obtained automatically or specified
                //We don't want to add them when the program is closed if they weren't actually set
                //Unfortunately, neither WMI nor the NetworkInterface class provide information about this setting
                object regAddress = Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\" + adapter.Id, "NameServer", "");
                if (regAddress != null && regAddress.ToString().Length > 0)
                {
                    dnsServers = NetworkManager.getDNS(adapter.Description);
                }

                NetworkListItem item = new NetworkListItem(adapter.Description, dnsServers);
                DNSlistbox.Items.Add(item);

                /*
                IPAddressCollection dnsServers2 = adapterProperties.DnsAddresses;
                if (dnsServers2.Count > 0)
                {
                    //NetworkListItem item = new NetworkListItem(adapter.Description, dnsServers2);
                    //DNSlistbox.Items.Add(item);

                    Console.WriteLine(adapter.Description + ": " + adapter.Id);
                    foreach (IPAddress dns in dnsServers2)
                    {
                        Console.WriteLine("  DNS Servers ............................. : {0}",
                            dns.ToString());
                    }
                    Console.WriteLine();
                }*/
            }
        }
        /// <summary>
        /// Fills the ListBox with information about each NIC
        /// </summary>
        private void GetNICs(Boolean showHidden)
        {
            this.ipv6Radio.Enabled = false;

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                List<string> dnsServers = new List<string>();	//More accurate than IPInterfaceProperties.DnsAddresses
                List<string> dnsServersv6 = new List<string>();

                //Determine if the DNS addresses are obtained automatically or specified
                //We don't want to add them when the program is closed if they weren't actually set
                //Unfortunately, neither WMI nor the NetworkInterface class provide information about this setting
                dnsServers = NetworkManager.getDNS(adapter.Id);
                dnsServersv6 = NetworkManager.getDNSv6(adapter.Id);

                NetworkListItem item = new NetworkListItem(adapter.Name, adapter.Description, dnsServers, dnsServersv6, adapter.Supports(NetworkInterfaceComponent.IPv4), adapter.Supports(NetworkInterfaceComponent.IPv6));
                if (!item.hidden || showHidden)
                {
                    DNSlistbox.Items.Add(item);

                    //See if the device supports IPv6 and enable the option if so
                    if (item.IPv6)
                    {
                        this.ipv6Radio.Enabled = true;
                    }
                }

                /*
                IPAddressCollection dnsServers2 = adapterProperties.DnsAddresses;
                if (dnsServers2.Count > 0)
                {
                    //NetworkListItem item = new NetworkListItem(adapter.Description, dnsServers2);
                    //DNSlistbox.Items.Add(item);

                    Console.WriteLine(adapter.Description + ": " + adapter.Id);
                    foreach (IPAddress dns in dnsServers2)
                    {
                        Console.WriteLine("  DNS Servers ............................. : {0}", dns.ToString());
                    }
                    Console.WriteLine();
                }*/
            }
        }
示例#4
0
        /// <summary>
        /// Fills the ListBox with information about each NIC
        /// </summary>
        private void GetNICs(Boolean showHidden, Boolean refresh)
        {
            this.ipv6Radio.Enabled = false;

            int i = 0;

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();

                List <string> dnsServers   = new List <string>();
                List <string> dnsServersv6 = new List <string>();

                //Determine if the DNS addresses are obtained automatically or specified
                //We don't want to add them when the program is closed if they weren't actually set
                //Unfortunately, neither WMI nor the NetworkInterface class provide information about this setting
                dnsServers   = NetworkManager.getDNS(adapter.Id);
                dnsServersv6 = NetworkManager.getDNSv6(adapter.Id);

                NetworkListItem item = new NetworkListItem(adapter.Id, adapter.Name, adapter.Description, dnsServers, dnsServersv6, adapter.Supports(NetworkInterfaceComponent.IPv4), adapter.Supports(NetworkInterfaceComponent.IPv6));
                if (!item.hidden || showHidden)
                {
                    if (refresh == false)
                    {
                        if (dnsServers.Count != 0)
                        {
                            if (dnsServers[0] == "127.0.0.1")
                            {
                                DNSlistbox.Items.Add(item, true);
                            }
                            else
                            {
                                DNSlistbox.Items.Add(item, false);
                            }
                        }
                        else
                        {
                            DNSlistbox.Items.Add(item, false);
                        }


                        //See if the device supports IPv6 and enable the option if so
                        if (item.IPv6)
                        {
                            this.ipv6Radio.Enabled = true;
                        }
                    }
                    else
                    {
                        if (DNSlistbox.Items.Count != 0)
                        {
                            DNSlistbox.Items[i] = item;

                            //See if the device supports IPv6 and enable the option if so
                            if (item.IPv6)
                            {
                                this.ipv6Radio.Enabled = true;
                            }
                        }
                    }
                }



                i++;

                /*
                 * IPAddressCollection dnsServers2 = adapterProperties.DnsAddresses;
                 * if (dnsServers2.Count > 0)
                 * {
                 *      //NetworkListItem item = new NetworkListItem(adapter.Description, dnsServers2);
                 *      //DNSlistbox.Items.Add(item);
                 *
                 *      Console.WriteLine(adapter.Description + ": " + adapter.Id);
                 *      foreach (IPAddress dns in dnsServers2)
                 *      {
                 *          Console.WriteLine("  DNS Servers ............................. : {0}", dns.ToString());
                 *      }
                 *      Console.WriteLine();
                 * }*/
            }
        }