public bool PerformScan_DoublePointArray(ScanOperation scanOperation) { if (_instCtrl == null) { return(false); } _currentScanOperation = scanOperation; _staThread.Invoke(new NoReturnAndParamDelegate(() => { #if NO_FINCH _instCtrl.PerformScan_DoublePointArray(); #endif }), null); return(true); }
/// <summary> /// Method that is called when Scan Button is clicked /// </summary> /// <param name="sender">The object that called this method</param> /// <param name="e">The RoutedEventArgs</param> private void BtnScan_Click(object sender, RoutedEventArgs e) { if (IntStart.Value == null || IntStop.Value == null) { return; } if (IntStart.Value > IntStop.Value) { MessageBox.Show("The starting port cannot be greater than the ending port!", "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (_operations != null && _operations.Count > 0) { MessageBox.Show("A previous scan is still running or in the process of being cancelled!", "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Error); return; } LvPorts.Items.Clear(); ControlsEnabled(false); PgbStatus.Value = 0; TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal; TaskbarItemInfo.ProgressValue = 0; _completedThreads = 0; PgbStatus.Minimum = (double)IntStart.Value - 1; PgbStatus.Maximum = (double)IntStop.Value; int totalTasks = Properties.Settings.Default.ScanThreads; int timeout = Properties.Settings.Default.TimeOut; int scanAmount = ((int)IntStop.Value - (int)IntStart.Value) + 1; int startPort = (int)IntStart.Value; TxtAddress.Text = TxtAddress.Text.Replace("https://", ""); TxtAddress.Text = TxtAddress.Text.Replace("http://", ""); TxtAddress.Text = TxtAddress.Text.Replace("ftp://", ""); TxtAddress.Text = TxtAddress.Text.Replace("sftp://", ""); string ipAddress = TxtAddress.Text; List <Action> functions = new List <Action>(); foreach (int i in ThreadCalculator.GetActionsPerThreads(totalTasks, scanAmount)) { int endPort = startPort + i - 1; int startPortCopy = startPort; ScanOperation scan = new ScanOperation { Progress = new Progress <int>(value => { PgbStatus.Value += 1; TaskbarItemInfo.ProgressValue += (1 / (PgbStatus.Maximum - PgbStatus.Minimum)); }), ItemProgress = new Progress <LvCheck>(value => LvPorts.Items.Add(value)), IsCancelled = false }; scan.ScanCompletedEvent += ScanThreadCompleted; _operations.Add(scan); switch (CbaMethod.Text) { default: functions.Add(() => PortScanner.CheckTCP(ipAddress, startPortCopy, endPort, timeout, scan, true)); break; case "UDP": functions.Add(() => PortScanner.CheckUDP(ipAddress, startPortCopy, endPort, timeout, scan, true)); break; case "Both": functions.Add(() => PortScanner.CheckTCPUDP(ipAddress, startPortCopy, endPort, timeout, scan)); break; } startPort = endPort + 1; } foreach (Action action in functions) { Thread thread = new Thread(new ThreadStart(action)) { IsBackground = true }; thread.Start(); } }