예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            AdapterInfo adapter = cbAdapters.SelectedItem as AdapterInfo;

            if (adapter != null)
            {
                uint result;

                try
                {
                    if (cbAutomatic.Checked)
                    {
                        result = adapter.SetDNSAutomatic();
                    }
                    else
                    {
                        string primaryDNS   = txtPreferredDNS.Text.Trim();
                        string secondaryDNS = txtAlternateDNS.Text.Trim();

                        if (Helpers.IsValidIPAddress(primaryDNS) && Helpers.IsValidIPAddress(secondaryDNS))
                        {
                            result = adapter.SetDNS(primaryDNS, secondaryDNS);
                        }
                        else
                        {
                            throw new Exception("Not valid IP address.");
                        }
                    }

                    if (result == 0)
                    {
                        NativeMethods.DnsFlushResolverCache();
                        MessageBox.Show("DNS successfully set.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == 1)
                    {
                        MessageBox.Show("DNS successfully set. Reboot is required.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result > 1)
                    {
                        MessageBox.Show("Setting DNS failed with error code: " + result, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Setting DNS failed.\r\n" + ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
        private void cbAdapters_SelectedIndexChanged(object sender, EventArgs e)
        {
            AdapterInfo adapter = cbAdapters.SelectedItem as AdapterInfo;

            if (adapter != null)
            {
                string[] dns = adapter.GetDNS();

                if (dns != null && dns.Length == 2)
                {
                    cbAutomatic.Checked  = false;
                    txtPreferredDNS.Text = dns[0];
                    txtAlternateDNS.Text = dns[1];
                }
                else
                {
                    cbAutomatic.Checked = true;
                }

                cbDNSType.SelectedIndex = 0;
            }

            UpdateControls();
        }
예제 #3
0
        public DNSChangerForm()
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;

            AddDNS("Manual");
            AddDNS("Google Public DNS", "8.8.8.8", "8.8.4.4");              // https://developers.google.com/speed/public-dns/
            AddDNS("OpenDNS", "208.67.222.222", "208.67.220.220");          // http://www.opendns.com/
            AddDNS("Level 3 Communications", "4.2.2.1", "4.2.2.2");         // http://www.level3.com/
            AddDNS("Norton ConnectSafe", "199.85.126.10", "199.85.127.10"); // https://dns.norton.com/
            AddDNS("Comodo Secure DNS", "8.26.56.26", "8.20.247.20");       // http://www.comodo.com/secure-dns/
            AddDNS("DNS Advantage", "156.154.70.1", "156.154.71.1");        // http://www.neustar.biz/services/dns-services/free-recursive-dns
            AddDNS("Yandex DNS", "77.88.8.2", "77.88.8.88");                // http://dns.yandex.com/

            foreach (AdapterInfo adapter in AdapterInfo.GetEnabledAdapters())
            {
                cbAdapters.Items.Add(adapter);
            }

            if (cbAdapters.Items.Count > 0)
            {
                cbAdapters.SelectedIndex = 0;
            }
        }