From 2ef1f5473bfc102108ad0a8d412dc5e2262775e5 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 11 Mar 2019 09:00:07 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 41 ++++++++++++ Program.cs | 125 +++++++++++++++++++++++++++++++++++ Properties/AssemblyInfo.cs | 35 ++++++++++ Target.cs | 26 ++++++++ entities/NetworkInterface.cs | 21 ++++++ entities/Node.cs | 30 +++++++++ identify/NodeIdentifier.cs | 118 +++++++++++++++++++++++++++++++++ ln.skyscanner.csproj | 68 +++++++++++++++++++ packages.config | 4 ++ 9 files changed, 468 insertions(+) create mode 100644 .gitignore create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Target.cs create mode 100644 entities/NetworkInterface.cs create mode 100644 entities/Node.cs create mode 100644 identify/NodeIdentifier.cs create mode 100644 ln.skyscanner.csproj create mode 100644 packages.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf793ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db +.vs/ + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..579ec32 --- /dev/null +++ b/Program.cs @@ -0,0 +1,125 @@ +// /** +// * File: Program.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 Renci.SshNet; +using ln.skyscanner.identify; +using System.Net; +using System.Collections.Generic; +using ln.snmp.types; +using System.IO; +using ln.snmp; +using ln.snmp.channel; +using System.Diagnostics; +using ln.perfdb.storage; +using ln.logging; + +namespace ln.skyscanner +{ + class MainClass + { + + private static void DumpPerfValues(PerfValue[] perfValues) + { + int n = 0; + + Logging.Log("----------------------------------------------"); + Logging.Log("Dumping {0} perfValues:", perfValues.Length); + foreach (PerfValue perfValue in perfValues) + { + Logging.Log("PerfValue: [{1,6}] {0}", perfValue, n); + n++; + } + Logging.Log(""); + } + + public static void Main(string[] args) + { + + //PerfFile perfFile = new PerfFile("test.lnpv"); + //perfFile.Open(); + + //if (perfFile.FirstSection == null) + //{ + // PerfFile.PerfFileSection section = new PerfFile.PerfFileSection(perfFile, null, 1440, 60, AggregationMethod.AVERAGE); + // section = new PerfFile.PerfFileSection(perfFile, section,1728,300, AggregationMethod.AVERAGE); + // section = new PerfFile.PerfFileSection(perfFile, section, 2016, 900, AggregationMethod.AVERAGE); + // section = new PerfFile.PerfFileSection(perfFile, section, 1344, 3600, AggregationMethod.AVERAGE); + // section = new PerfFile.PerfFileSection(perfFile, section, 1344, 10800, AggregationMethod.AVERAGE); + //} + + //int n = 10; + //for (long ts = 1000; ts < 160000; ts += 60) + //{ + // perfFile.Write(ts, n++); + //} + + //PerfValue[] dump = new PerfValue[perfFile.FirstSection.nRecords]; + + //perfFile.FirstSection.ReadRecords(dump, 0, 0, dump.Length); + //DumpPerfValues(dump); + + //DumpPerfValues(perfFile.QueryTime(3600, 0)); + //DumpPerfValues(perfFile.QueryTime(3600 * 24, 0)); + //DumpPerfValues(perfFile.QueryTime(3600 * 24, 3600)); + + + //perfFile.Close(); + + //return; + + SNMPEngine.DEBUG = true; + + SNMPEngine engine = new SNMPEngine(); + engine.Timeout = 3000; + + SnmpV1Endpoint v1endpoint = new SnmpV1Endpoint(engine, new IPEndPoint(IPAddress.Parse("10.113.254.4"), 161), "ghE7wUmFPoPpkRno"); + SnmpV2Endpoint v2endpoint = new SnmpV2Endpoint(engine, new IPEndPoint(IPAddress.Parse("10.113.254.4"), 161), "ghE7wUmFPoPpkRno"); + + USMEndpoint v3endpoint = new USMEndpoint(engine, new IPEndPoint(IPAddress.Parse("10.255.3.41"), 161)); + v3endpoint.AuthMethod = SnmpV3AuthMethod.SHA; + v3endpoint.AuthKey = "qVy3hnZJ2fov"; + v3endpoint.Username = "skytron"; + + SNMPInterface intf = v3endpoint; + + Stopwatch stopWatch = Stopwatch.StartNew(); + Sequence[][] ifTable = intf.snmpWalk(new String[] { + "1.3.6.1.2.1.2.2.1.2", + "1.3.6.1.2.1.2.2.1.10", + "1.3.6.1.2.1.2.2.1.16", + "1.3.6.1.2.1.2.2.1.14", + "1.3.6.1.2.1.2.2.1.20" + }); + stopWatch.Stop(); + + Console.WriteLine("Time for table walk: {0}ms", stopWatch.ElapsedMilliseconds); + + foreach (Sequence[] sequences in ifTable) + { + foreach (Sequence sequence in sequences) + { + Console.Write("{0}\t", sequence?.Items[1].Value); + } + Console.WriteLine(""); + } + + engine.Close(); + + //NodeIdentifier identifier = new NodeIdentifier(IPAddress.Parse("10.10.10.1")); + //identifier.Identify(); + + //foreach (KeyValuePair hint in identifier.Hints) + //{ + // Console.WriteLine("{0:16} = {1}", hint.Key, hint.Value); + //} + + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..45e92e8 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +// /** +// * File: AssemblyInfo.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.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("ln.skyscanner")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("${AuthorCopyright}")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Target.cs b/Target.cs new file mode 100644 index 0000000..d124ece --- /dev/null +++ b/Target.cs @@ -0,0 +1,26 @@ +// /** +// * File: Target.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.Net; +namespace ln.skyscanner +{ + public class Target + { + public IPAddress TargetIP { get; set; } + public int CheckIntervall { get; set; } + + public Target(IPAddress targetIP) + { + TargetIP = targetIP; + } + + + } +} diff --git a/entities/NetworkInterface.cs b/entities/NetworkInterface.cs new file mode 100644 index 0000000..74fff26 --- /dev/null +++ b/entities/NetworkInterface.cs @@ -0,0 +1,21 @@ +// /** +// * File: NetworkInterface.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; +namespace ln.skyscanner.entities +{ + public class NetworkInterface + { + public Node Node { get; private set; } + public NetworkInterface(Node node) + { + Node = node; + } + } +} diff --git a/entities/Node.cs b/entities/Node.cs new file mode 100644 index 0000000..4c64f79 --- /dev/null +++ b/entities/Node.cs @@ -0,0 +1,30 @@ +// /** +// * File: IPNode.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; +namespace ln.skyscanner.entities +{ + public class Node + { + public Guid ID { get; private set; } + + public Node() + { + ID = Guid.NewGuid(); + } + public Node(Guid guid) + { + ID = guid; + } + + + + + } +} diff --git a/identify/NodeIdentifier.cs b/identify/NodeIdentifier.cs new file mode 100644 index 0000000..ae5ece3 --- /dev/null +++ b/identify/NodeIdentifier.cs @@ -0,0 +1,118 @@ +// /** +// * File: NodeIdentifier.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.Net; +using Renci.SshNet; +using System.Net.Sockets; +using System.Text; +using System.IO.Pipes; +using System.IO; +using System.Threading; +namespace ln.skyscanner.identify +{ + public class NodeIdentifier + { + static KeyValuePair[] sshAuthorizations = new KeyValuePair[] + { + new KeyValuePair("skytron","67E3xpTcMbwR"), + new KeyValuePair("skytron","v1kXbeCux0Td"), + new KeyValuePair("skytron","DVqxof1JQ9at") + }; + + + public IPAddress Host { get; } + public Dictionary Hints => hints; + + Dictionary hints = new Dictionary(); + + public NodeIdentifier(IPAddress host) + { + Host = host; + } + + public void Identify() + { + TestSSH(); + } + + public void TestSSH() + { + byte[] buffer = new byte[256]; + int l; + + TcpClient tcp = new TcpClient(); + try + { + SshClient ssh; + + tcp.Connect(new IPEndPoint(Host, 13022)); + tcp.ReceiveTimeout = 2500; + l = tcp.GetStream().Read(buffer, 0, buffer.Length); + tcp.Close(); + + hints.Add("SSH-CONNECT", Encoding.UTF8.GetString(buffer, 0, l)); + + Console.WriteLine("SSH-Connect-Banner: {0}", hints["SSH-CONNECT"]); + + + foreach (KeyValuePair auth in sshAuthorizations) + { + ssh = new SshClient(Host.ToString(), 13022, auth.Key, auth.Value); + ssh.Connect(); + if (ssh.IsConnected) + { + ssh.Disconnect(); + hints.Add("SSH-LOGIN", auth.Key); + hints.Add("SSH-PASSWORD", auth.Value); + break; + } + ssh.Disconnect(); + } + + if (!hints.ContainsKey("SSH-LOGIN")) + return; + + ssh = new SshClient(Host.ToString(), 13022, hints["SSH-LOGIN"], hints["SSH-PASSWORD"]); + ssh.Connect(); + + try + { + hints.Add("SSH_AVAILABLE", "YES"); + hints.Add("SSH-VERSION", ssh.ConnectionInfo.ServerVersion); + + MemoryStream stdout = new MemoryStream(); + MemoryStream stderr = new MemoryStream(); + + Shell shell = ssh.CreateShell(Encoding.UTF8, "", stdout, stderr); + shell.Start(); + Thread.Sleep(500); + shell.Stop(); + + hints.Add("SSH-SHELL-BANNER", Encoding.UTF8.GetString(stdout.GetBuffer())); + + ssh.Disconnect(); + } catch (Exception e) + { + Console.WriteLine(e); + + if (ssh.IsConnected) + ssh.Disconnect(); + } + } catch (Exception e) + { + hints.Add("SSH_AVAILABLE", "NO"); + Console.WriteLine(e); + } + } + + + } +} diff --git a/ln.skyscanner.csproj b/ln.skyscanner.csproj new file mode 100644 index 0000000..dba5a58 --- /dev/null +++ b/ln.skyscanner.csproj @@ -0,0 +1,68 @@ + + + + Debug + x86 + {8456AFA0-20E9-4566-A81A-3C0EDB12356F} + Exe + ln.skyscanner + ln.skyscanner + v4.7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + true + bin\Release + prompt + 4 + true + x86 + + + + + ..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll + + + + + + + + + + + + + + + + + + + + + {C7A43B82-55F2-4092-8DBE-6BE29CBF079D} + ln.snmp + + + {D934C1E8-9215-4D8D-83B3-A296E4912792} + ln.perfdb + + + {D471A566-9FB6-41B2-A777-3C32874ECD0E} + ln.logging + + + + \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..8dac18b --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file