/// <summary> /// Test network scanning /// </summary> private static async Task TestNetworkScannerAsync() { var logger = ConsoleOutLogger.Create(); using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10))) { var watch = Stopwatch.StartNew(); var scanning = new ScanServices(logger); var results = await scanning.ScanAsync(NetworkClass.Wired, cts.Token); foreach (var result in results) { Console.WriteLine($"Found {result.Address}..."); } Console.WriteLine($"Scan took: {watch.Elapsed}"); } }
/// <summary> /// Test port scanning /// </summary> private static async Task TestPortScannerAsync(string host, bool opc) { var logger = ConsoleOutLogger.Create(); var addresses = await Dns.GetHostAddressesAsync(host); using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10))) { var watch = Stopwatch.StartNew(); var scanning = new ScanServices(logger); var results = await scanning.ScanAsync( PortRange.All.SelectMany(r => r.GetEndpoints(addresses.First())), opc?new ServerProbe(logger) : null, cts.Token); foreach (var result in results) { Console.WriteLine($"Found {result} open."); } Console.WriteLine($"Scan took: {watch.Elapsed}"); } }
/// <summary> /// Test port scanning /// </summary> /// <param name="host"></param> /// <returns></returns> private static async Task TestPortScanner(string host) { var logger = new ConsoleLogger("test", LogLevel.Debug); var addresses = await Dns.GetHostAddressesAsync(host); var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10)); var watch = Stopwatch.StartNew(); var scanning = new ScanServices(logger); DumpMemory(); var results = await scanning.ScanAsync( PortRange.All.SelectMany(r => r.GetEndpoints(addresses.First())), cts.Token); foreach (var result in results) { Console.WriteLine($"Found {result} open."); } Console.WriteLine($"Scan took: {watch.Elapsed}"); DumpMemory(); }