Example #1
0
        private void AddEditDevice_Load(object sender, EventArgs e)
        {
            if (IsEditMode)
            {
                this.Text = "Edit Device " + DeviceName;
            }
            else
            {
                this.Text = "Add New Device";
            }

            if (IsEditMode)
            {
                txbDeviceName.Text        = DeviceName;
                txbDeviceDescription.Text = DeviceDescription;
                btnSelectDeviceType.Text  = SurgitManager.ReadableString(DeviceTType) + " (click to change)";
                txbDeviceHostname.Text    = DeviceHostname;
                txbDeviceIPv4.Text        = DeviceIPv4;
                txbDeviceIPv6.Text        = DeviceIPv6;
                txbDeviceMac.Text         = DeviceMac;

                OriginalDeviceMac = DeviceMac;

                btnAdd.Text = "Update Device";
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool ipStartValid;

            // Check if start-IP is valid
            if (IPAddress.TryParse(txbIPRangeStart.Text, out IPAddress ipStartRange) && ipStartRange.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipStartValid = true;
            }
            else
            {
                MessageBox.Show("The given range-start is not a valid IPv4-Address", "Invalid IP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool ipEndValid;

            // Check if end-IP is valid
            if (IPAddress.TryParse(txbIPRangeEnd.Text, out IPAddress ipEndRange) && ipEndRange.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipEndValid = true;
            }
            else
            {
                MessageBox.Show("The given range-end is not a valid IPv4-Address", "Invalid IP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check if the start and end IPs are in the same subnet and that they are in a class C subnet
            if (ipStartValid && ipEndValid && SurgitManager.CheckIPClassCValidity(txbIPRangeStart.Text, txbIPRangeEnd.Text))
            {
                IPStartRange = txbIPRangeStart.Text;
                IPEndRange   = txbIPRangeEnd.Text;

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("The given range is not valid. Make sure the IPs are in the same subnet. Note: Only C-Class IP-Adresses are currently supported", "Invalid Range", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        private void BtnStartDiscovery_Click(object sender, EventArgs e)
        {
            bool ipStartValid;

            // Check if start-IP is valid
            if (IPAddress.TryParse(txbDiscoveryStart.Text, out IPAddress ipStartRange) && ipStartRange.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipStartValid = true;
            }
            else
            {
                MessageBox.Show("The given range-start is not a valid IPv4-Address", "Invalid IP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool ipEndValid;

            // Check if end-IP is valid
            if (IPAddress.TryParse(txbDiscoveryEnd.Text, out IPAddress ipEndRange) && ipEndRange.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                ipEndValid = true;
            }
            else
            {
                MessageBox.Show("The given range-end is not a valid IPv4-Address", "Invalid IP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check if the start and end IPs are in the same subnet and that they are in a class C subnet
            if (ipStartValid && ipEndValid && SurgitManager.CheckIPClassCValidity(txbDiscoveryStart.Text, txbDiscoveryEnd.Text))
            {
                if (!bgwDiscovery.IsBusy)
                {
                    bgwDiscovery.RunWorkerAsync();
                }
            }
            else
            {
                MessageBox.Show("The given range is not valid. Make sure the IPs are in the same subnet. Note: Only C-Class IP-Adresses are currently supported", "Invalid Range", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }