/// <summary> /// Scans the local network and synchronizes the located systems details with the /// configured <c>Snipe.It</c> system. /// </summary> private void SyncScannerDetails() { var subnetsToScan = subnetString .Split("|".ToArray(), StringSplitOptions.RemoveEmptyEntries); var devices = IPScanner .Scan(subnetsToScan) .Where(i => i.Status == System.Net.NetworkInformation.IPStatus.Success) .ToList(); foreach (var item in devices) { this.SyncHostNameDetails(item.HostName); } }
/// <summary> /// Scans the through the specified collection of network subnets for active IP addresses. /// </summary> /// <param name="subnet"> /// The collection of subnets (192.168.1 | 192.168.2) that to scan. /// </param> /// <returns> /// The network scan results. /// </returns> public static IEnumerable <IPScannerResult> Scan(string[] subnet) { ConcurrentBag <IPScannerResult> results = new ConcurrentBag <IPScannerResult>(); var ipAddresses = subnet.SelectMany(s => Enumerable.Range(1, 255).Select(i => s + "." + i)); Parallel.ForEach(ipAddresses, new ParallelOptions() { MaxDegreeOfParallelism = 5 }, i => { var result = IPScanner.ScanAddress(i); if (result != null) { results.Add(result); } }); return(results.ToList()); }