public async Task Run(IOutputInput outputInput) { this.outputInput = outputInput; var address = Common.GetLocalAddress(outputInput); if (address == null) { return; } var mask = NetworkUtils.GetSubnetMask(address); var port = Common.GetPort(outputInput, 9989); if (port == 0) { return; } var addresses = NetworkUtils.GetAddressesInNetwork(address, mask); if (addresses.Count == 0) { outputInput.WriteLine("No addresses to scan"); return; } outputInput.WriteLine("Current IP address: " + address.ToString()); outputInput.WriteLine("Mask: " + mask.ToString()); outputInput.WriteLine("Addresses to scan: " + addresses.Count); outputInput.WriteLine("Port to scan: " + port); outputInput.WriteLine("Scan started!"); var scanner = new ServiceScanner() { StopOnFirstException = false, TasksCount = 0 }; scanner.OnScanProgress += ServiceScanner_OnScanProgress; outputInput.StartTime(); var result = await scanner.ServiceScan(new ServiceScanInput { Addresses = addresses, Port = port, Retries = 1, Timeout = 1000 }, new TCPPortClient()); outputInput.StopTime(); var processed = result.GetResults(); outputInput.WriteLine($"Scan completed. Scanned addresses: {processed.Count}, found services: {result.Count(r => r.Output)}"); return; }
public async Task Run(IOutputInput outputInput) { this.outputInput = outputInput; var address = Common.GetLocalAddress(outputInput); if (address == null) { return; } var portsString = outputInput.Read("Insert ports (comma separated):", "80, 135, 9989"); var ports = new List <int>(); if (!string.IsNullOrEmpty(portsString)) { foreach (var port in portsString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()) { if (int.TryParse(port, out int p) && !ports.Contains(p)) { ports.Add(p); } } } if (ports.Count == 0) { outputInput.WriteLine("No ports provided"); return; } ports.Sort(); outputInput.WriteLine("Current IP address: " + address.ToString()); outputInput.WriteLine("Ports to scan: " + string.Join(", ", ports.Select(s => s.ToString()))); outputInput.WriteLine("TCP Scan started!"); var scanner = new PortScanner() { StopOnFirstException = false, TasksCount = 0 }; scanner.OnScanProgress += PortScanner_OnScanProgress; outputInput.StartTime(); var result = await scanner.PortScan(new PortScanInput { Addresses = new List <IPAddress> { address }, Ports = ports, Retries = 1, Timeout = 1000 }, new TCPPortClient()); outputInput.StopTime(); var processed = result.GetResults(); outputInput.WriteLine($"Scan completed. Scanned addresses: {processed.Count}, total scanned ports: {processed.Sum(s => s.Count)}"); }
public async Task Run(IOutputInput outputInput) { var queue = new Queue(outputInput); var numbers = Enumerable.Range(1, 5); var items = numbers.Select(s => new ProcessingQueueItem <int, int>(s)).ToList(); queue.TasksCount = 1; outputInput.WriteLine($"Processing started with {queue.TasksCount} task"); outputInput.StartTime(); await queue.Run(items); outputInput.WriteLine($"Processed {items.Count(i => i.Processed)} items"); outputInput.StopTime(); queue.TasksCount = 4; outputInput.WriteLine($"Processing started with {queue.TasksCount} tasks"); outputInput.StartTime(); await queue.Run(items); outputInput.WriteLine($"Processed {items.Count(i => i.Processed)} items"); outputInput.StopTime(); queue.TasksCount = 1; var delay = 3000; var cts = new CancellationTokenSource(delay); outputInput.WriteLine($"Processing started with {queue.TasksCount} tasks. Will be cancelled in {delay}ms"); outputInput.StartTime(); await queue.Run(items, cts.Token); outputInput.WriteLine($"Processed {items.Count(i => i.Processed)} items"); outputInput.StopTime(); queue.TasksCount = 1; queue.StopOnFirstException = true; queue.Throw = true; outputInput.WriteLine($"Processing started with {queue.TasksCount} tasks. Will crash soon"); outputInput.StartTime(); await queue.Run(items); outputInput.WriteLine($"Processed {items.Count(i => i.Processed)} items"); outputInput.StopTime(); }
public async Task Run(IOutputInput outputInput) { this.outputInput = outputInput; var address = Common.GetLocalAddress(outputInput); if (address == null) { return; } var mask = NetworkUtils.GetSubnetMask(address); var addresses = NetworkUtils.GetAddressesInNetwork(address, mask); if (addresses.Count == 0) { outputInput.WriteLine("No addresses to scan"); return; } outputInput.WriteLine("Current IP address: " + address.ToString()); outputInput.WriteLine("Mask: " + mask.ToString()); outputInput.WriteLine("Addresses to scan: " + addresses.Count); outputInput.WriteLine("Scan started!"); var pingScanner = new PingScanner() { StopOnFirstException = false, TasksCount = 0 }; pingScanner.OnScanProgress += PingScanner_OnScanProgress; outputInput.StartTime(); var result = await pingScanner.PingScan(new PingScanInput { Addresses = addresses, Retries = 1, Timeout = 1000 }); outputInput.StopTime(); var processed = result.GetResults(); var found = processed.Where(s => s.Reply?.Status == IPStatus.Success); outputInput.WriteLine($"Scan completed. Scanned addresses: {processed.Count}, found {found.Count()} devices"); }