ln.skyscanner/crawl/CrawlPool.cs

68 lines
1.6 KiB
C#

// /**
// * 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<CrawledHost> hosts = new List<CrawledHost>();
public List<Subnet> Subnets = new List<Subnet>();
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;
}
}
}
}