ln.skyscanner/crawl/CrawledHost.cs

111 lines
3.0 KiB
C#
Raw Normal View History

2019-03-13 08:20:53 +01:00
// /**
// * 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;
2019-03-15 07:43:12 +01:00
using System.Linq;
using ln.snmp;
using ln.snmp.endpoint;
2019-03-18 08:12:54 +01:00
using ln.snmp.rfc1213;
2019-03-21 07:43:32 +01:00
2019-03-13 08:20:53 +01:00
namespace ln.skyscanner.crawl
{
2019-03-15 07:43:12 +01:00
public class CrawledHost
2019-03-13 08:20:53 +01:00
{
2019-03-18 08:12:54 +01:00
private List<RFC1213.Interface> interfaces = new List<RFC1213.Interface>();
public RFC1213.Interface[] Interfaces
{
get => interfaces.ToArray();
set => interfaces = new List<RFC1213.Interface>(value);
}
public String[] HWAddresses => interfaces.Select((intf) => intf.HWAddr).ToArray();
public String PrimaryHWAddr => HWAddresses.Where((hwa) => hwa != null && !String.Empty.Equals(hwa)).FirstOrDefault();
2019-03-13 08:20:53 +01:00
2019-03-15 07:43:12 +01:00
public String Name { get; set; }
public CIDR PrimaryIP { get; set; }
2019-03-13 08:20:53 +01:00
2019-03-21 07:43:32 +01:00
public CIDR[] IPAddresses
{
get
{
CIDR[] result = interfaces.Select((intf) => intf.IPAddresses).SelectMany((i) => i).ToArray();
if (result.Length == 0)
return new CIDR[] { PrimaryIP };
return result;
}
}
2019-03-18 08:12:54 +01:00
2019-03-15 07:43:12 +01:00
Dictionary<string, object> hints = new Dictionary<string, object>();
2019-03-13 08:20:53 +01:00
2019-03-15 07:43:12 +01:00
public DateTime FirstSeen;
public DateTime LastSeen;
public DateTime LastCheck;
public DateTime NextCheck;
2019-03-21 07:43:32 +01:00
public TimeSpan LastCheckTime;
2019-03-13 08:20:53 +01:00
2019-03-18 08:12:54 +01:00
public bool SnmpDetected => GetHint<int>("snmp.version", -1) != -1;
2019-03-21 07:43:32 +01:00
public bool SSHDetected => GetHint<int>("ssh.port", -1) != -1;
public bool RFC1213Detected => GetHint<bool>("rfc1213", false);
2019-03-18 08:12:54 +01:00
2019-03-15 07:43:12 +01:00
public CrawledHost()
2019-03-13 08:20:53 +01:00
{
2019-03-15 07:43:12 +01:00
Name = "noname";
PrimaryIP = IPAddress.Any;
}
2019-03-13 08:20:53 +01:00
2019-03-15 07:43:12 +01:00
public KeyValuePair<string, object>[] Hints => hints.ToArray();
public void SetHint(string name,object value)
{
hints[name] = value;
}
public object GetHint(String name)
{
return hints[name];
2019-03-13 08:20:53 +01:00
}
2019-03-15 07:43:12 +01:00
public T GetHint<T>(string name)
2019-03-13 08:20:53 +01:00
{
2019-03-15 07:43:12 +01:00
return (T)GetHint(name);
}
public object GetHint(string name,object def)
{
if (HasHint(name))
return hints[name];
2019-03-13 08:20:53 +01:00
2019-03-15 07:43:12 +01:00
return def;
2019-03-13 08:20:53 +01:00
}
2019-03-15 07:43:12 +01:00
public T GetHint<T>(string name,T def)
2019-03-13 08:20:53 +01:00
{
2019-03-15 07:43:12 +01:00
if (HasHint(name))
return (T)hints[name];
return def;
2019-03-13 08:20:53 +01:00
}
2019-03-15 07:43:12 +01:00
public bool HasHint(string name)
2019-03-13 08:20:53 +01:00
{
2019-03-15 07:43:12 +01:00
return hints.ContainsKey(name) && (hints[name] != null);
}
2019-03-13 08:20:53 +01:00
public override string ToString()
{
2019-03-18 08:12:54 +01:00
return String.Format("[CrawledHost PrimaryIP={0} Name={1}]",PrimaryIP,Name);
2019-03-13 08:20:53 +01:00
}
}
}