2014-03-22 14:39:28 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2015-08-13 13:07:38 +12:00
|
|
|
|
Copyright (c) 2007-2015 ShareX Team
|
2014-03-22 14:39:28 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib.Properties;
|
2014-03-22 14:39:28 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2015-09-01 06:36:50 +12:00
|
|
|
|
public partial class DNSChangerForm : BaseForm
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
|
|
|
|
public DNSChangerForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2014-10-18 00:08:33 +13:00
|
|
|
|
AddDNS(Resources.DNSChangerForm_DNSChangerForm_Manual);
|
2014-03-29 19:58:41 +13:00
|
|
|
|
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/
|
2014-03-23 07:56:31 +13:00
|
|
|
|
|
2014-03-23 11:39:05 +13:00
|
|
|
|
foreach (AdapterInfo adapter in AdapterInfo.GetEnabledAdapters())
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
|
|
|
|
cbAdapters.Items.Add(adapter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cbAdapters.Items.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
cbAdapters.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 19:58:41 +13:00
|
|
|
|
private void AddDNS(string name, string primary = null, string secondary = null)
|
|
|
|
|
{
|
|
|
|
|
cbDNSType.Items.Add(new DNSInfo(name, primary, secondary));
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 14:39:28 +13:00
|
|
|
|
private void cbAdapters_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AdapterInfo adapter = cbAdapters.SelectedItem as AdapterInfo;
|
|
|
|
|
|
|
|
|
|
if (adapter != null)
|
|
|
|
|
{
|
|
|
|
|
string[] dns = adapter.GetDNS();
|
|
|
|
|
|
2014-03-22 16:16:35 +13:00
|
|
|
|
if (dns != null && dns.Length == 2)
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
cbAutomatic.Checked = false;
|
|
|
|
|
txtPreferredDNS.Text = dns[0];
|
|
|
|
|
txtAlternateDNS.Text = dns[1];
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
2014-03-23 07:56:31 +13:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cbAutomatic.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbDNSType.SelectedIndex = 0;
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
UpdateControls();
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
private void cbAutomatic_CheckedChanged(object sender, EventArgs e)
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
UpdateControls();
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
private void cbDNSType_SelectedIndexChanged(object sender, EventArgs e)
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
if (cbDNSType.SelectedIndex > 0)
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
DNSInfo dnsInfo = cbDNSType.SelectedItem as DNSInfo;
|
2014-03-22 14:39:28 +13:00
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
if (dnsInfo != null)
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
txtPreferredDNS.Text = dnsInfo.PrimaryDNS;
|
|
|
|
|
txtAlternateDNS.Text = dnsInfo.SecondaryDNS;
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
UpdateControls();
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtPreferredDNS_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
UpdateControls();
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtAlternateDNS_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-03-23 07:56:31 +13:00
|
|
|
|
UpdateControls();
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
private void UpdateControls()
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-23 12:15:13 +13:00
|
|
|
|
cbDNSType.Enabled = !cbAutomatic.Checked;
|
|
|
|
|
txtPreferredDNS.Enabled = !cbAutomatic.Checked && cbDNSType.SelectedIndex == 0;
|
|
|
|
|
txtAlternateDNS.Enabled = !cbAutomatic.Checked && cbDNSType.SelectedIndex == 0;
|
2014-03-23 07:56:31 +13:00
|
|
|
|
}
|
2014-03-22 14:39:28 +13:00
|
|
|
|
|
2014-04-01 01:18:51 +13:00
|
|
|
|
private void SendPing(string ip)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(ip))
|
|
|
|
|
{
|
|
|
|
|
btnPingPrimary.Enabled = btnPingSecondary.Enabled = false;
|
|
|
|
|
|
2014-05-24 03:39:14 +12:00
|
|
|
|
TaskEx.Run(() =>
|
2014-04-01 01:18:51 +13:00
|
|
|
|
{
|
|
|
|
|
PingResult pingResult = PingHelper.PingHost(ip);
|
2014-10-18 01:19:28 +13:00
|
|
|
|
MessageBox.Show(pingResult.ToString(), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2014-05-22 13:48:27 +12:00
|
|
|
|
},
|
|
|
|
|
() =>
|
2014-04-01 01:18:51 +13:00
|
|
|
|
{
|
|
|
|
|
btnPingPrimary.Enabled = btnPingSecondary.Enabled = true;
|
2014-05-22 13:48:27 +12:00
|
|
|
|
});
|
2014-04-01 01:18:51 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AdapterInfo adapter = cbAdapters.SelectedItem as AdapterInfo;
|
2014-03-22 14:39:28 +13:00
|
|
|
|
|
2014-03-23 07:56:31 +13:00
|
|
|
|
if (adapter != null)
|
|
|
|
|
{
|
2014-03-31 23:23:56 +13:00
|
|
|
|
uint result;
|
2014-03-23 07:56:31 +13:00
|
|
|
|
|
2014-03-31 23:23:56 +13:00
|
|
|
|
try
|
2014-03-22 14:39:28 +13:00
|
|
|
|
{
|
2014-03-31 23:23:56 +13:00
|
|
|
|
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
|
|
|
|
|
{
|
2014-04-01 00:23:47 +13:00
|
|
|
|
throw new Exception("Not valid IP address.");
|
2014-03-31 23:23:56 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-23 07:56:31 +13:00
|
|
|
|
|
2014-03-31 23:23:56 +13:00
|
|
|
|
if (result == 0)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.DnsFlushResolverCache();
|
2014-10-18 00:08:33 +13:00
|
|
|
|
MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_DNS_successfully_set_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2014-03-31 23:23:56 +13:00
|
|
|
|
}
|
|
|
|
|
else if (result == 1)
|
2014-03-23 07:56:31 +13:00
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_DNS_successfully_set__Reboot_is_required_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2014-03-31 23:23:56 +13:00
|
|
|
|
}
|
|
|
|
|
else if (result > 1)
|
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_Setting_DNS_failed_with_error_code_ + " " + result, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2014-03-23 07:56:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-31 23:23:56 +13:00
|
|
|
|
catch (Exception ex)
|
2014-03-23 07:56:31 +13:00
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
MessageBox.Show(Resources.DNSChangerForm_btnSave_Click_Setting_DNS_failed_ + "\r\n" + ex, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-23 07:56:31 +13:00
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2014-04-01 01:18:51 +13:00
|
|
|
|
|
|
|
|
|
private void btnPingPrimary_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SendPing(txtPreferredDNS.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnPingSecondary_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SendPing(txtAlternateDNS.Text);
|
|
|
|
|
}
|
2014-03-22 14:39:28 +13:00
|
|
|
|
}
|
|
|
|
|
}
|