// /** // * File: CrawlPool.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.Collections.Generic; using ln.types; using System.Net; using System.Linq; using ln.skyscanner.entities; namespace ln.skyscanner.crawl { public class CrawlPool { public List hosts = new List(); public List Subnets = new List(); public CrawlPool() { } public CrawledHost[] Hosts => hosts.ToArray(); public CrawledHost HostForIP(CIDR ip) { lock (this) { foreach (CrawledHost host in hosts) { if (host.IPAddresses.Contains(ip) || ip.Equals(host.PrimaryIP)) return host; } CrawledHost h = new CrawledHost(); h.PrimaryIP = ip; h.Name = ip.ToString(); hosts.Add(h); return h; } } public Subnet GetSubnet(CIDR network) { lock (this) { foreach (Subnet subnet in Subnets) { if (subnet.Network.Equals(network)) return subnet; } Subnet net = new Subnet(network); Subnets.Add(net); return net; } } } }