78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
// /**
|
|
// * File: CrawledHost.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 System.Security.Cryptography.X509Certificates;
|
|
using ln.types;
|
|
using ln.types.sync;
|
|
using System.Net;
|
|
using System.IO;
|
|
using System.Net.NetworkInformation;
|
|
using ln.logging;
|
|
namespace ln.skyscanner.crawl
|
|
{
|
|
public class CrawledHost : Syncable
|
|
{
|
|
[Unsynced]
|
|
private Crawler crawler;
|
|
public Crawler Crawler { get => crawler; set => crawler = value; }
|
|
|
|
private Guid id;
|
|
public Guid ID { get => id; set => id = value; }
|
|
|
|
private List<CIDR> ipaddresses = new List<CIDR>();
|
|
public List<CIDR> IPAddresses => ipaddresses;
|
|
|
|
|
|
|
|
public CrawledHost()
|
|
{ }
|
|
|
|
public CrawledHost(Crawler crawler)
|
|
{
|
|
Crawler = crawler;
|
|
ID = Guid.NewGuid();
|
|
|
|
FileName = Path.Combine(crawler.BasePath, String.Format("{0}.ch", ID.ToString()));
|
|
}
|
|
public CrawledHost(Crawler crawler, Guid id)
|
|
:this(crawler)
|
|
{
|
|
ID = id;
|
|
FileName = Path.Combine(crawler.BasePath, String.Format("{0}.ch", ID.ToString()));
|
|
|
|
Load();
|
|
}
|
|
public CrawledHost(Crawler crawler, string filename)
|
|
: base(filename)
|
|
{
|
|
}
|
|
|
|
public void Crawl()
|
|
{
|
|
Logging.Log(LogLevel.INFO, "Checking {0}", id);
|
|
|
|
Ping ping = new Ping();
|
|
|
|
foreach (CIDR ip in IPAddresses)
|
|
{
|
|
PingReply pingReply = ping.Send(ip);
|
|
Logging.Log(LogLevel.INFO, "IP {0} Ping: {1}",ip,pingReply.RoundtripTime);
|
|
}
|
|
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[CrawledHost ID={0} IPAddress=({1})]",ID,String.Join(", ",IPAddresses));
|
|
}
|
|
}
|
|
}
|