Exemple #1
0
        public Form1()
        {
            InitializeComponent();
            //Icon = ShareXResources.Icon;

            AddDNS("自定义方案&默认方案", "", "");
            AddDNS("Pure DNS", "123.207.137.88", "115.159.220.214");
            AddDNS("Xsico DNS", "115.159.96.69", "122.114.245.45");
            AddDNS("Mogu DNS", "122.114.245.45", "115.159.96.69");
            AddDNS("AIXYZ DNS", "115.159.146.99", "123.206.21.48");
            AddDNS("中科大DNS 电信", "202.141.162.123", "202.141.162.123");
            AddDNS("中科大DNS 移动", "202.141.176.93", "202.141.176.93");
            AddDNS("中科大DNS 教育网", "202.38.93.153", "202.141.162.123");



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

            if (cbAdapters.Items.Count > 0)
            {
                cbAdapters.SelectedIndex = 0;
            }
        }
Exemple #2
0
        public Form1()
        {
            InitializeComponent();
            //Icon = ShareXResources.Icon;

            AddDNS(Resources.DNSChangerForm_DNSChangerForm_Manual);
            AddDNS("阿里DNS", "223.5.5.5", "223.6.6.6");
            AddDNS("腾讯DNS", "119.29.29.29", "182.254.116.116");
            AddDNS("CNNIC SDNS", "1.2.4.8", "210.2.4.8");
            AddDNS("114 DNS", "114.114.114.114", "114.114.115.115");
            AddDNS("oneDNS", "112.124.47.27", "114.215.126.16");
            AddDNS("DNS派 电信/移动/铁通", "101.226.4.6", "218.30.118.6");
            AddDNS("DNS派 联通", "123.125.81.6", "140.207.198.6");
            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;
            }
        }
Exemple #3
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("无法验证IP");
                        }
                    }

                    if (result == 0)
                    {
                        NativeMethods.DnsFlushResolverCache();
                        MessageBox.Show("DNS成功更新", "已完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == 1)
                    {
                        MessageBox.Show("DNS成功更新,但需要重启", "已完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result > 1)
                    {
                        MessageBox.Show("DNS更新出错" + " " + result, "已完成", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("DNS更新失败" + "\r\n" + ex, "已完成", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #4
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(Resources.DNSChangerForm_btnSave_Click_DNS_successfully_set_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == 1)
                    {
                        MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_DNS_successfully_set__Reboot_is_required_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result > 1)
                    {
                        MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_Setting_DNS_failed_with_error_code_ + " " + result, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_Setting_DNS_failed_ + "\r\n" + ex, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #5
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 = false;
                }

                cbDNSType.SelectedIndex = 0;
            }

            UpdateControls();
        }