124 lines
3.3 KiB
C#
124 lines
3.3 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 ln.types;
|
|
using System.Net;
|
|
using System.Linq;
|
|
using ln.snmp.rfc1213;
|
|
using LiteDB;
|
|
using ln.types.odb;
|
|
|
|
namespace ln.skyscanner.crawl
|
|
{
|
|
public class CrawledHost
|
|
{
|
|
[DocumentID]
|
|
public readonly Guid ID = Guid.NewGuid();
|
|
|
|
public String Name { get; set; }
|
|
public CIDR PrimaryIP { get; set; }
|
|
|
|
public String[] HWAddresses = new string[0];
|
|
public String PrimaryHWAddr => HWAddresses.Where((hwa) => hwa != null && !String.Empty.Equals(hwa)).FirstOrDefault();
|
|
|
|
public CIDR[] IPAddresses { get; set; } = new CIDR[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 = IPAddress.Any;
|
|
}
|
|
|
|
public bool HasIP(CIDR ip)
|
|
{
|
|
foreach (CIDR _ip in IPAddresses)
|
|
if (_ip.Host.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;
|
|
}
|
|
}
|
|
}
|