Initial Commit

broken
Harald Wolff 2019-03-11 09:00:07 +01:00
commit 2ef1f5473b
9 changed files with 468 additions and 0 deletions

41
.gitignore vendored 100644
View File

@ -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

125
Program.cs 100644
View File

@ -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<string,string> hint in identifier.Hints)
//{
// Console.WriteLine("{0:16} = {1}", hint.Key, hint.Value);
//}
}
}
}

View File

@ -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("")]

26
Target.cs 100644
View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

30
entities/Node.cs 100644
View File

@ -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;
}
}
}

View File

@ -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<string, string>[] sshAuthorizations = new KeyValuePair<string, string>[]
{
new KeyValuePair<string, string>("skytron","67E3xpTcMbwR"),
new KeyValuePair<string, string>("skytron","v1kXbeCux0Td"),
new KeyValuePair<string, string>("skytron","DVqxof1JQ9at")
};
public IPAddress Host { get; }
public Dictionary<string, String> Hints => hints;
Dictionary<string, string> hints = new Dictionary<string, string>();
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<string,string> 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);
}
}
}
}

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{8456AFA0-20E9-4566-A81A-3C0EDB12356F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ln.skyscanner</RootNamespace>
<AssemblyName>ln.skyscanner</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Renci.SshNet">
<HintPath>..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="identify\NodeIdentifier.cs" />
<Compile Include="Target.cs" />
<Compile Include="entities\Node.cs" />
<Compile Include="entities\NetworkInterface.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="identify\" />
<Folder Include="check\" />
<Folder Include="entities\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ln.snmp\ln.snmp.csproj">
<Project>{C7A43B82-55F2-4092-8DBE-6BE29CBF079D}</Project>
<Name>ln.snmp</Name>
</ProjectReference>
<ProjectReference Include="..\ln.perfdb\ln.perfdb.csproj">
<Project>{D934C1E8-9215-4D8D-83B3-A296E4912792}</Project>
<Name>ln.perfdb</Name>
</ProjectReference>
<ProjectReference Include="..\ln.logging\ln.logging.csproj">
<Project>{D471A566-9FB6-41B2-A777-3C32874ECD0E}</Project>
<Name>ln.logging</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

4
packages.config 100644
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SSH.NET" version="2016.1.0" targetFramework="net47" />
</packages>