예제 #1
0
        private void SwapDNS()
        {
            if (NIC_select.SelectedIndex != -1 && string.IsNullOrEmpty(IPerrorProvider.GetError(DNS_1)) && string.IsNullOrEmpty(IPerrorProvider.GetError(DNS_2)))
            {
                // Get current DNS server

                IPAddress DNS_servers = NetworkManagement.getDNS(NIC_select.SelectedItem.ToString());
                if (DNS_servers.Equals(IPAddress.Parse(Regex.Replace(DNS_1.Text, @"\s+", ""))))
                {
                    callSwapDNS(NIC_select.SelectedItem.ToString(), Regex.Replace(DNS_2.Text, @"\s+", ""));
                    IPAddress ip = NetworkManagement.getDNS(NIC_select.SelectedItem.ToString());
                    if (ip.Equals(IPAddress.Parse(Regex.Replace(DNS_2.Text, @"\s+", ""))))
                    {
                        taskBarIcon.Icon = Resource1.icon_blue;
                        Icon             = Resource1.icon_blue;
                        changeToggleBtnPosition(true);
                    }
                    else
                    {
                        taskBarIcon.Icon = Resource1.error;
                    }
                }
                else if (DNS_servers.Equals(IPAddress.Parse(Regex.Replace(DNS_2.Text, @"\s+", ""))))
                {
                    callSwapDNS(NIC_select.SelectedItem.ToString(), Regex.Replace(DNS_1.Text, @"\s+", ""));

                    if (NetworkManagement.getDNS(NIC_select.SelectedItem.ToString()).Equals(IPAddress.Parse(Regex.Replace(DNS_1.Text, @"\s+", ""))))
                    {
                        taskBarIcon.Icon = Resource1.icon_red;
                        Icon             = Resource1.icon_red;
                        changeToggleBtnPosition(false);
                    }
                    else
                    {
                        taskBarIcon.Icon = Resource1.error;
                    }
                }
                else
                {
                    MessageBox.Show("Couldn't find any of the given DNS servers configured on the selected network interface", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                NetworkManagement.FlushDNSCache();
            }
            else
            {
                MessageBox.Show("Please select a network interface and enter 2 valid IPs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        public MainMenu()
        {
            InitializeComponent();
            //WindowState = FormWindowState.Minimized;
            //ShowInTaskbar = false;
            //this.Hide();

            // Load network interfaces
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    if (!NIC_select.Items.Cast <string>().Contains(nic.Description))
                    {
                        NIC_select.Items.Add(nic.Description);
                    }
                }
            }

            // Load previously saved user settings
            NIC_select.SelectedItem = Properties.Settings.Default.NIC;
            DNS_1.Text = Properties.Settings.Default.DNS_1;
            DNS_2.Text = Properties.Settings.Default.DNS_2;

            if (NIC_select.SelectedItem != null && !string.IsNullOrEmpty(DNS_1.Text) && !string.IsNullOrEmpty(DNS_2.Text))
            {
                if (NetworkManagement.getDNS().Equals(IPAddress.Parse(DNS_1.Text)))
                {
                    taskBarIcon.Icon = Resource1.icon_red;
                    changeToggleBtnPosition(false);
                }
                else if (NetworkManagement.getDNS().Equals(IPAddress.Parse(DNS_2.Text)))
                {
                    taskBarIcon.Icon = Resource1.icon_blue;
                    changeToggleBtnPosition(true);
                }
            }
        }
예제 #3
0
        public MainMenu()
        {
            InitializeComponent();
            //WindowState = FormWindowState.Minimized;
            //ShowInTaskbar = false;
            //this.Hide();

            // Load network interfaces
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    if (!NIC_select.Items.Cast <string>().Contains(nic.Description))
                    {
                        NIC_select.Items.Add(nic.Description);
                    }
                }
            }

            // Load previously saved user settings
            NIC_select.SelectedItem = Properties.Settings.Default.NIC;
            // Remove blank in IP-Address
            string DNS1_var = Properties.Settings.Default.DNS_1.Replace(" ", string.Empty);
            string DNS2_var = Properties.Settings.Default.DNS_2.Replace(" ", string.Empty);
            // Variables used for validated IP-Addresses
            IPAddress DNS1_IP = new IPAddress(new byte[] { 127, 0, 0, 1 });
            IPAddress DNS2_IP = new IPAddress(new byte[] { 127, 0, 0, 1 });

            if (string.IsNullOrEmpty(DNS1_var) || string.IsNullOrEmpty(DNS2_var))
            {
                // No DNS servers configured
                MessageBox.Show("Tool not configured yet", "DNS-Swapper configuration missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Show();
                WindowState   = FormWindowState.Normal;
                ShowInTaskbar = true;
            }
            else
            {
                // Validate configuration
                if ((IPAddress.TryParse(DNS1_var, out DNS1_IP)) && (IPAddress.TryParse(DNS2_var, out DNS2_IP)))
                {
                    // DNS server IPs valid
                    // Set Loaded variables into settings text boxes
                    DNS_1.Text = DNS1_var;
                    DNS_2.Text = DNS2_var;

                    if (NIC_select.SelectedItem != null && !string.IsNullOrEmpty(DNS_1.Text) && !string.IsNullOrEmpty(DNS_2.Text))
                    {
                        if (NetworkManagement.getDNS().Equals(DNS1_IP))
                        {
                            taskBarIcon.Icon = Resource1.icon_red;
                            changeToggleBtnPosition(false);
                        }
                        else if (NetworkManagement.getDNS().Equals(DNS2_IP))
                        {
                            taskBarIcon.Icon = Resource1.icon_blue;
                            changeToggleBtnPosition(true);
                        }
                    }
                }
                else
                {
                    // DNS server IP(s) invalid - give error
                    MessageBox.Show("Invalid configuration detected. Resetting settings to default", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    resetToolStripMenuItem_Click(null, null);
                    saveSettings();
                    Show();
                    WindowState   = FormWindowState.Normal;
                    ShowInTaskbar = true;
                }
            }
        }
예제 #4
0
        public MainMenu()
        {
            AutoUpdater.Start("https://www.tryallthethings.xyz/downloads/DNS-Swapper.xml");

            InitializeComponent();

            // Upgrade settings file (user.config in %LOCALAPPDATA%\DNS_Swapper from previous version
            Settings.Default.Upgrade();

            // Load network interfaces
            scanNICs();

            // Load previously saved user settings
            NIC_select.SelectedIndex = NIC_select.FindStringExact(Settings.Default.NIC);

            // Remove blank in IP-Address
            string DNS1_var = Settings.Default.DNS_1.Replace(" ", string.Empty);
            string DNS2_var = Settings.Default.DNS_2.Replace(" ", string.Empty);
            // Variables used for validated IP-Addresses
            IPAddress DNS1_IP = new IPAddress(new byte[] { 127, 0, 0, 1 });
            IPAddress DNS2_IP = new IPAddress(new byte[] { 127, 0, 0, 1 });

            if (string.IsNullOrEmpty(DNS1_var) || string.IsNullOrEmpty(DNS2_var))
            {
                // No DNS servers configured
                MessageBox.Show("Tool not configured yet", "DNS-Swapper configuration missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Show();
                WindowState   = FormWindowState.Normal;
                ShowInTaskbar = true;
            }
            else
            {
                // Validate configuration
                if (IPAddress.TryParse(DNS1_var, out DNS1_IP) && IPAddress.TryParse(DNS2_var, out DNS2_IP))
                {
                    // DNS server IPs valid
                    // Set Loaded variables into settings text boxes
                    DNS_1.Text = DNS1_var;
                    DNS_2.Text = DNS2_var;

                    // Set taskbar icon color
                    if (NIC_select.SelectedItem != null && !string.IsNullOrEmpty(DNS_1.Text) && !string.IsNullOrEmpty(DNS_2.Text))
                    {
                        if (NetworkManagement.getDNS(NIC_select.SelectedItem.ToString()).Equals(DNS1_IP))
                        {
                            taskBarIcon.Icon = Resource1.icon_red;
                            changeToggleBtnPosition(false);
                        }
                        else if (NetworkManagement.getDNS(NIC_select.SelectedItem.ToString()).Equals(DNS2_IP))
                        {
                            taskBarIcon.Icon = Resource1.icon_blue;
                            changeToggleBtnPosition(true);
                        }
                    }
                }
                else
                {
                    // DNS server IP(s) invalid - display error message
                    MessageBox.Show("Invalid configuration detected. Resetting settings to default", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    resetToolStripMenuItem_Click(null, null);
                    saveSettings();
                    Show();
                    WindowState   = FormWindowState.Normal;
                    ShowInTaskbar = true;
                }
            }
        }