// Read scan mode radio button selection private ScannerManagerSingleton.ScanMode ReadScanMode() { if (tcpModeRadioButton.Checked) { currentScanMode = ScannerManagerSingleton.ScanMode.TCP; Logger.Info("Current Scan Mode: " + currentScanMode); } else { currentScanMode = ScannerManagerSingleton.ScanMode.UDP; Logger.Info("Current Scan Mode: " + currentScanMode); } return(currentScanMode); }
// Executed when the Check Port button is clicked private void checkPortButton_Click(object sender, EventArgs e) { // Get user inputs string hostname = hostnameTextBox.Text; if (hostname == "") { MessageBox.Show("Please enter a valid hostname.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); hostnameTextBox.Focus(); return; } // Check port int portMin = InputChecker.ParsePort(portTextBoxMin.Text); if (portMin == -1) { MessageBox.Show((portRangeCheckBox.Checked ? "Lower limit of port range" : "Port") + " invalid.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); portTextBoxMin.Focus(); return; } // Get scan mode ScannerManagerSingleton.ScanMode scanMode = ReadScanMode(); // If custom timeout time, verify correct user input int timeout; if (IsTimeoutComboBoxUserInput()) { // If valid, proceed with that input as timeout timeout = InputChecker.ParseTimeout(timeoutComboBox.Text); if (timeout == -1) { MessageBox.Show("Timeout format: [time], [time]ms or [time] ms.\nTimeout must be between 250 ms and 20000 ms.", "Timeout Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { // Else, use the ValueMember of the selected Member timeout = (int)timeoutComboBox.SelectedValue; } // Instantiate CTS cts = new CancellationTokenSource(); // Simple one port check if (!portRangeCheckBox.Checked) { // Set status box text var connectionText = String.Format("Connecting to {0}, port {1}...{2}", hostname, portMin, Environment.NewLine); statusTextBox.AppendText(connectionText); Logger.Info(connectionText); // The callback for scan result var callback = new ExecuteOnceAsyncCallback(PortResult); // Send one check request and toggle user inputs ToggleInputs(false); smc.ExecuteOnceAsync(hostname, portMin, timeout, scanMode, callback, cts.Token); } // Port range check else { // Verify input int portMax = InputChecker.ParsePort(portTextBoxMax.Text); if (portMax == -1) { MessageBox.Show("Upper limit of port range invalid.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); portTextBoxMax.Focus(); return; } if (portMax < portMin) { MessageBox.Show("Port range invalid.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); portTextBoxMax.Focus(); return; } // The callback for scan result var callback = new ExecuteOnceAsyncCallback(PortResult); // Set status box text var connectionText = String.Format("Connecting to {0}, port {1}...{2}", hostname, portMin, Environment.NewLine); statusTextBox.AppendText(connectionText); Logger.Info(connectionText); // Toggle inputs and begin operation ToggleInputs(false); smc.ExecuteRangeAsync(hostname, portMin, portMax, timeout, scanMode, callback, cts.Token); } }