ln.skyscanner/crawl/CrawledHost.cs

120 lines
3.2 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.Linq;
using ln.types.net;
namespace ln.skyscanner.crawl
{
public class CrawledHost
{
public readonly Guid ID = Guid.NewGuid();
public String Name { get; set; }
public IPv4 PrimaryIP { get; set; }
public String[] HWAddresses = new string[0];
public String PrimaryHWAddr => HWAddresses.Where((hwa) => hwa != null && !String.Empty.Equals(hwa)).FirstOrDefault();
public IPv4[] IPAddresses { get; set; } = new IPv4[0];
public Network4[] Networks { get; set; } = new Network4[0];
Dictionary<string, object> hints = new Dictionary<string, object>();
public DateTime FirstSeen { get; set; }
public DateTime LastSeen { get; set; }
public DateTime LastCheck { get; set; }
public DateTime NextCheck { get; set; }
public TimeSpan LastCheckTime { get; set; }
public bool SnmpDetected => GetHint<int>("snmp.version", -1) != -1;
public bool SSHDetected => GetHint<int>("ssh.port", -1) != -1;
public bool RFC1213Detected => GetHint<bool>("rfc1213", false);
public CrawledHost()
{
Name = "noname";
PrimaryIP = IPv4.ANY;
}
public bool HasIP(IPv4 ip)
{
foreach (IPv4 _ip in IPAddresses)
if (_ip.Equals(ip))
return true;
return false;
}
public KeyValuePair<string, object>[] Hints
{
get => hints.ToArray();
private set
{
hints = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> kv in value)
hints.Add(kv.Key, kv.Value);
}
}
public void SetHint(string name,object value)
{
hints[name] = value;
}
public object GetHint(String name)
{
return hints[name];
}
public T GetHint<T>(string name)
{
return (T)GetHint(name);
}
public object GetHint(string name,object def)
{
if (HasHint(name))
return hints[name];
return def;
}
public T GetHint<T>(string name,T def)
{
if (HasHint(name))
return (T)hints[name];
return def;
}
public bool HasHint(string name)
{
return hints.ContainsKey(name) && (hints[name] != null);
}
public override string ToString()
{
return String.Format("[CrawledHost PrimaryIP={0} Name={1}]",PrimaryIP,Name);
}
public override int GetHashCode()
{
return ID.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is CrawledHost)
{
CrawledHost you = obj as CrawledHost;
return ID.Equals(you.ID);
}
return false;
}
}
}