WIP
parent
ed2c104cf7
commit
48585ea3e1
59
Program.cs
59
Program.cs
|
@ -34,6 +34,8 @@ using Castle.DynamicProxy;
|
||||||
using ln.types.odb;
|
using ln.types.odb;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using ln.skyscanner.entities;
|
using ln.skyscanner.entities;
|
||||||
|
using ln.types.btree;
|
||||||
|
using ln.types.test;
|
||||||
|
|
||||||
namespace ln.skyscanner
|
namespace ln.skyscanner
|
||||||
{
|
{
|
||||||
|
@ -43,8 +45,11 @@ namespace ln.skyscanner
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
new testODB().TestCase();
|
||||||
|
return;
|
||||||
|
|
||||||
FileLogger fileLogger = new FileLogger("skyscanner.log");
|
FileLogger fileLogger = new FileLogger("skyscanner.log");
|
||||||
fileLogger.MaxLogLevel = LogLevel.DEBUG;
|
fileLogger.MaxLogLevel = LogLevel.INFO;
|
||||||
Logger.Default.Backends.Add(fileLogger);
|
Logger.Default.Backends.Add(fileLogger);
|
||||||
|
|
||||||
Logger.ConsoleLogger.MaxLogLevel = LogLevel.INFO;
|
Logger.ConsoleLogger.MaxLogLevel = LogLevel.INFO;
|
||||||
|
@ -61,41 +66,41 @@ namespace ln.skyscanner
|
||||||
//using (ODB odb = new ODB("odb"))
|
//using (ODB odb = new ODB("odb"))
|
||||||
//{
|
//{
|
||||||
|
|
||||||
//ODBCollection col = odb.GetCollection("test");
|
//ODBCollection col = odb.GetCollection("test");
|
||||||
|
|
||||||
//foreach (ODBDocument odoc in col)
|
//foreach (ODBDocument odoc in col)
|
||||||
//{
|
//{
|
||||||
// Console.WriteLine("Stored DOC: {0}", odoc);
|
// Console.WriteLine("Stored DOC: {0}", odoc);
|
||||||
// if (!odoc.Contains("counter"))
|
// if (!odoc.Contains("counter"))
|
||||||
// odoc["counter"] = 0;
|
// odoc["counter"] = 0;
|
||||||
// else
|
// else
|
||||||
// odoc["counter"] = odoc["counter"].AsInt + 1;
|
// odoc["counter"] = odoc["counter"].AsInt + 1;
|
||||||
|
|
||||||
// col.Upsert(odoc);
|
// col.Upsert(odoc);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//ODBDocument doc = new ODBDocument();
|
//ODBDocument doc = new ODBDocument();
|
||||||
|
|
||||||
//doc["snmp.msg"] = "Hallo WelT!";
|
//doc["snmp.msg"] = "Hallo WelT!";
|
||||||
//doc["name"] = "Harald";
|
//doc["name"] = "Harald";
|
||||||
//doc["alter"] = 39;
|
//doc["alter"] = 39;
|
||||||
//doc["genauer"] = 34.5;
|
//doc["genauer"] = 34.5;
|
||||||
//ODBDocument ndoc = new ODBDocument();
|
//ODBDocument ndoc = new ODBDocument();
|
||||||
//doc["keywords"] = ndoc;
|
//doc["keywords"] = ndoc;
|
||||||
|
|
||||||
//ndoc["eins"] = 1;
|
//ndoc["eins"] = 1;
|
||||||
//ndoc["zwei"] = 2;
|
//ndoc["zwei"] = 2;
|
||||||
//ndoc["drei"] = 3;
|
//ndoc["drei"] = 3;
|
||||||
|
|
||||||
//Console.WriteLine(doc);
|
//Console.WriteLine(doc);
|
||||||
|
|
||||||
//col.Insert(doc);
|
//col.Insert(doc);
|
||||||
|
|
||||||
//Node node = new Node(CIDR.Parse("1.2.3.4"));
|
//Node node = new Node(CIDR.Parse("1.2.3.4"));
|
||||||
//ODBDocument nodeDoc = ODBMapper.Default.ToODBValue(node).AsDocument;
|
//ODBDocument nodeDoc = ODBMapper.Default.ToODBValue(node).AsDocument;
|
||||||
//Console.WriteLine("Node: {0}", nodeDoc);
|
//Console.WriteLine("Node: {0}", nodeDoc);
|
||||||
|
|
||||||
//Node node2 = ODBMapper.Default.ToNativeValue<Node>(nodeDoc);
|
//Node node2 = ODBMapper.Default.ToNativeValue<Node>(nodeDoc);
|
||||||
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace ln.skyscanner
|
||||||
public ODB odDatabase { get; private set; }
|
public ODB odDatabase { get; private set; }
|
||||||
public ODBCollection<Node> nodeCollection { get; private set; }
|
public ODBCollection<Node> nodeCollection { get; private set; }
|
||||||
public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
||||||
|
public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
||||||
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
||||||
|
|
||||||
public SkyEntities(SkyScanner skyScanner)
|
public SkyEntities(SkyScanner skyScanner)
|
||||||
|
@ -33,8 +34,12 @@ namespace ln.skyscanner
|
||||||
odDatabase = new ODB(BasePath);
|
odDatabase = new ODB(BasePath);
|
||||||
nodeCollection = odDatabase.GetCollection<Node>();
|
nodeCollection = odDatabase.GetCollection<Node>();
|
||||||
interfaceCollection = odDatabase.GetCollection<NetworkInterface>();
|
interfaceCollection = odDatabase.GetCollection<NetworkInterface>();
|
||||||
|
intfIPCollection = odDatabase.GetCollection<IntfIP>();
|
||||||
subnetCollection = odDatabase.GetCollection<Subnet>();
|
subnetCollection = odDatabase.GetCollection<Subnet>();
|
||||||
|
|
||||||
|
interfaceCollection.EnsureIndex("NodeID");
|
||||||
|
intfIPCollection.EnsureIndex("interfaceID");
|
||||||
|
|
||||||
GlobalNetwork = new GlobalNetwork(this);
|
GlobalNetwork = new GlobalNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ using ln.types;
|
||||||
using ln.types.odb;
|
using ln.types.odb;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.crawl
|
||||||
{
|
{
|
||||||
public class CrawledSubnet
|
public class CrawledSubnet
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,8 @@ using ln.types.odb;
|
||||||
using ln.types.sync;
|
using ln.types.sync;
|
||||||
using ln.logging;
|
using ln.logging;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using ln.types.threads;
|
||||||
|
using ln.types.odb.values;
|
||||||
|
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
|
@ -61,13 +63,16 @@ namespace ln.skyscanner.entities
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Node> FindHostsInSubnet(CIDR network)
|
public IEnumerable<Node> FindHostsInSubnet(CIDR network)
|
||||||
{
|
{
|
||||||
return SkyEntities.nodeCollection.Select(node => network.Contains(node.IPAdresses));
|
IntfIP[] intfIPs = SkyEntities.intfIPCollection.Select((ip) => ip.IP.In(network)).ToArray();
|
||||||
|
NetworkInterface[] networkInterfaces = intfIPs.Select((iip) => iip.NetworkInterface).Distinct().ToArray();
|
||||||
|
Node[] nodes = SkyEntities.nodeCollection.Select(networkInterfaces.Select((ni) => (ODBValue)ni.NodeID).Distinct()).ToArray();
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Node> FindNeighbors(Node node)
|
public IEnumerable<Node> FindNeighbors(Node node)
|
||||||
{
|
{
|
||||||
return node.Interfaces.SelectMany((intf) => intf.IPs).SelectMany((arg) => FindHostsInSubnet(arg)).Distinct();
|
return node.IPAdresses.SelectMany((ip) => Timing.Meassure("FindHostsInSubnet", () => FindHostsInSubnet(ip)).Distinct().ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node FindNodeByIP(IEnumerable<CIDR> ips)
|
public Node FindNodeByIP(IEnumerable<CIDR> ips)
|
||||||
|
@ -83,7 +88,11 @@ namespace ln.skyscanner.entities
|
||||||
public Node FindNodeByIP(CIDR ip)
|
public Node FindNodeByIP(CIDR ip)
|
||||||
{
|
{
|
||||||
ip = ip.Host;
|
ip = ip.Host;
|
||||||
return SkyEntities.nodeCollection.Select(node => ip.In(node.IPAdresses) || ip.In(node.PrimaryIP)).FirstOrDefault();
|
|
||||||
|
IntfIP _iip = SkyEntities.intfIPCollection.Where((iip) => iip.IP.Host.Equals(ip)).FirstOrDefault();
|
||||||
|
if (_iip != null)
|
||||||
|
return _iip.NetworkInterface.Node;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Unsynced]
|
[Unsynced]
|
||||||
|
@ -146,13 +155,38 @@ namespace ln.skyscanner.entities
|
||||||
networkInterface = new NetworkInterface(node, fields[0]);
|
networkInterface = new NetworkInterface(node, fields[0]);
|
||||||
|
|
||||||
networkInterface.HWAddress = fields[1];
|
networkInterface.HWAddress = fields[1];
|
||||||
networkInterface.IPs = fields[2].Split(',').Where((sip)=> !String.Empty.Equals(sip)).Select((sip) => CIDR.Parse(sip)).ToArray();
|
|
||||||
|
|
||||||
SkyEntities.interfaceCollection.Upsert(networkInterface);
|
SkyEntities.interfaceCollection.Upsert(networkInterface);
|
||||||
|
|
||||||
foreach (CIDR ip in networkInterface.IPs)
|
CIDR[] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip)).Select((sip) => CIDR.Parse(sip)).ToArray();
|
||||||
EnsureSubnet(ip);
|
IntfIP[] currentIPs = networkInterface.IPs.ToArray();
|
||||||
|
|
||||||
|
foreach (CIDR crawledIP in crawledIPs)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
for (n=0; n < currentIPs.Length; n++)
|
||||||
|
if (currentIPs[n].IP.Equals(crawledIP))
|
||||||
|
break;
|
||||||
|
if (n == currentIPs.Length)
|
||||||
|
{
|
||||||
|
IntfIP miss = new IntfIP(networkInterface, crawledIP);
|
||||||
|
SkyEntities.intfIPCollection.Upsert(miss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (IntfIP iip in currentIPs)
|
||||||
|
{
|
||||||
|
CIDR ip = iip.IP;
|
||||||
|
|
||||||
|
if (crawledIPs.Contains(ip))
|
||||||
|
{
|
||||||
|
EnsureSubnet(ip.Network);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SkyEntities.intfIPCollection.Delete(iip);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node.RemoveURI("ssh");
|
node.RemoveURI("ssh");
|
||||||
|
|
|
@ -20,6 +20,8 @@ namespace ln.skyscanner.entities
|
||||||
public Node Node { get; private set; }
|
public Node Node { get; private set; }
|
||||||
public GlobalNetwork GlobalNetwork => SkyScanner.Instance.Entities.GlobalNetwork;
|
public GlobalNetwork GlobalNetwork => SkyScanner.Instance.Entities.GlobalNetwork;
|
||||||
|
|
||||||
|
public int MaxDepth { get; set; } = 2;
|
||||||
|
|
||||||
Dictionary<Node, int> hops = new Dictionary<Node, int>();
|
Dictionary<Node, int> hops = new Dictionary<Node, int>();
|
||||||
|
|
||||||
public HopMap()
|
public HopMap()
|
||||||
|
@ -53,7 +55,8 @@ namespace ln.skyscanner.entities
|
||||||
if (!hops.ContainsKey(node) || (hops[node] > level))
|
if (!hops.ContainsKey(node) || (hops[node] > level))
|
||||||
{
|
{
|
||||||
hops[node] = level;
|
hops[node] = level;
|
||||||
AddNodes(GlobalNetwork.FindNeighbors(node), level + 1);
|
if (level < MaxDepth)
|
||||||
|
AddNodes(GlobalNetwork.FindNeighbors(node), level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// /**
|
||||||
|
// * File: IntfIP.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 ln.types.odb;
|
||||||
|
using ln.types;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
namespace ln.skyscanner.entities
|
||||||
|
{
|
||||||
|
public class IntfIP
|
||||||
|
{
|
||||||
|
[DocumentID]
|
||||||
|
public readonly Guid ID = Guid.NewGuid();
|
||||||
|
|
||||||
|
Guid interfaceID = Guid.Empty;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public NetworkInterface NetworkInterface => SkyScanner.Instance.Entities.interfaceCollection.Select(interfaceID);
|
||||||
|
|
||||||
|
public CIDR IP { get; private set; }
|
||||||
|
|
||||||
|
public IntfIP()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public IntfIP(NetworkInterface networkInterface,CIDR ip)
|
||||||
|
{
|
||||||
|
interfaceID = networkInterface.ID;
|
||||||
|
IP = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
[DocumentID]
|
[DocumentID]
|
||||||
public readonly Guid ID = Guid.NewGuid();
|
public readonly Guid ID = Guid.NewGuid();
|
||||||
|
|
||||||
public Guid NodeID { get; set; }
|
public Guid NodeID { get; set; }
|
||||||
|
|
||||||
[JsonIgnoreAttribute]
|
[JsonIgnoreAttribute]
|
||||||
|
@ -33,7 +33,8 @@ namespace ln.skyscanner.entities
|
||||||
public string Name { get; private set; } = "";
|
public string Name { get; private set; } = "";
|
||||||
public string HWAddress { get; set; } = "";
|
public string HWAddress { get; set; } = "";
|
||||||
|
|
||||||
public CIDR[] IPs { get; set; } = new CIDR[0];
|
//public CIDR[] IPs { get; set; } = new CIDR[0];
|
||||||
|
public IEnumerable<IntfIP> IPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID);
|
||||||
|
|
||||||
private NetworkInterface()
|
private NetworkInterface()
|
||||||
{ }
|
{ }
|
||||||
|
@ -48,9 +49,9 @@ namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
ip = ip.Host;
|
ip = ip.Host;
|
||||||
|
|
||||||
foreach (CIDR ifip in IPs)
|
foreach (IntfIP ifip in IPs)
|
||||||
{
|
{
|
||||||
if (ifip.Contains(ip))
|
if (ifip.IP.Host.Equals(ip))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -14,6 +14,7 @@ using System.Linq;
|
||||||
using ln.types.odb;
|
using ln.types.odb;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using LiteDB;
|
using LiteDB;
|
||||||
|
using ln.types.threads;
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
public class Node
|
public class Node
|
||||||
|
@ -37,8 +38,10 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public string ProductLine { get; set; }
|
public string ProductLine { get; set; }
|
||||||
|
|
||||||
public IEnumerable<NetworkInterface> Interfaces => SkyScanner.Instance.Entities.interfaceCollection.Select( intf => intf.NodeID.Equals(ID));
|
public IEnumerable<NetworkInterface> Interfaces => Timing.Meassure("Node.Interfaces",
|
||||||
public IEnumerable<CIDR> IPAdresses => Interfaces.SelectMany(intf => intf.IPs);
|
() => SkyScanner.Instance.Entities.interfaceCollection.Select("NodeID", ID)
|
||||||
|
);
|
||||||
|
public IEnumerable<CIDR> IPAdresses => Timing.Meassure("Node.IPAddesses", () => Interfaces.SelectMany(intf => intf.IPs).Select((iip)=>iip.IP));
|
||||||
|
|
||||||
private HashSet<URI> uris = new HashSet<URI>();
|
private HashSet<URI> uris = new HashSet<URI>();
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public bool AutoScan { get; set; }
|
public bool AutoScan { get; set; }
|
||||||
|
|
||||||
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.IPs));
|
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.IPs.Select((iip)=>iip.IP)));
|
||||||
public IEnumerable<Node> AttachedNodes => AttachedInterfaces.Select(intf => intf.Node).Distinct();
|
public IEnumerable<Node> AttachedNodes => AttachedInterfaces.Select(intf => intf.Node).Distinct();
|
||||||
|
|
||||||
private Subnet()
|
private Subnet()
|
||||||
|
|
|
@ -48,8 +48,11 @@ namespace ln.skyscanner.http
|
||||||
public HopMap.HopNode[] GetHopTable()
|
public HopMap.HopNode[] GetHopTable()
|
||||||
{
|
{
|
||||||
HopMap hopMap = new HopMap();
|
HopMap hopMap = new HopMap();
|
||||||
foreach (Node node in GlobalNetwork.Nodes)
|
//foreach (Node node in GlobalNetwork.Nodes)
|
||||||
hopMap.AddNode(node, 0);
|
//hopMap.AddNode(node, 0);
|
||||||
|
|
||||||
|
hopMap.AddNode(GlobalNetwork.FindNodeByIP(CIDR.Parse("10.10.10.2")),0);
|
||||||
|
|
||||||
return hopMap.HopNodes;
|
return hopMap.HopNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
<Compile Include="http\NetworkApi.cs" />
|
<Compile Include="http\NetworkApi.cs" />
|
||||||
<Compile Include="crawl\service\CrawlService.cs" />
|
<Compile Include="crawl\service\CrawlService.cs" />
|
||||||
<Compile Include="crawl\service\TCP.cs" />
|
<Compile Include="crawl\service\TCP.cs" />
|
||||||
|
<Compile Include="entities\IntfIP.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|
Loading…
Reference in New Issue