90 lines
2.1 KiB
C#
90 lines
2.1 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;
|
|
using ln.types.odb;
|
|
namespace ln.skyscanner.crawl
|
|
{
|
|
public class CrawlPool : Persistent
|
|
{
|
|
private List<CrawledHost> hosts = new List<CrawledHost>();
|
|
private List<CrawledSubnet> subnets = new List<CrawledSubnet>();
|
|
|
|
public CrawlPool()
|
|
{
|
|
}
|
|
|
|
public CrawledHost[] Hosts {
|
|
get {
|
|
lock (this) { return hosts.ToArray(); };
|
|
}
|
|
}
|
|
|
|
public CrawledSubnet[] Subnets
|
|
{
|
|
get
|
|
{
|
|
lock (this)
|
|
{
|
|
return subnets.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 void RemoveHost(CrawledHost crawledHost)
|
|
{
|
|
hosts.Remove(crawledHost);
|
|
}
|
|
|
|
public CrawledSubnet GetSubnet(CIDR network)
|
|
{
|
|
lock (this)
|
|
{
|
|
foreach (CrawledSubnet subnet in subnets)
|
|
{
|
|
if (subnet.Network.Equals(network))
|
|
return subnet;
|
|
}
|
|
|
|
CrawledSubnet net = new CrawledSubnet(network);
|
|
subnets.Add(net);
|
|
return net;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|