Skip to content

Commit

Permalink
Lanscanner + Sonstiges
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoe8495 committed Oct 30, 2017
1 parent d871c8a commit 00f540a
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 83 deletions.
3 changes: 2 additions & 1 deletion BasePlugins/BasePlugins.csproj
Expand Up @@ -44,7 +44,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
<Compile Include="laninfo.cs" />
<Compile Include="LanInfo.cs" />
<Compile Include="NetworkTools.cs" />
<Compile Include="PluginInterface.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
85 changes: 85 additions & 0 deletions BasePlugins/NetworkTools.cs
@@ -0,0 +1,85 @@
using Heijden.DNS;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace NIHT.Plugins.Base {
public class NetworkTools {
public static bool Ping(string ip) {
return Ping(ip, 4);
}
public static bool Ping(string ip, int menge) {
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;

// Create a buffer of 32 bytes of data to be transmitted.
string data = "abcdefghijklmnopqrstuvwxyzabcdef";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
int success = 0;
Console.WriteLine("Ping wird ausgeführt für " + ip + " mit 32 Bytes Daten:");
for (int i = 0; i < menge; i++) {
PingReply reply = pingSender.Send(ip, timeout, buffer, options);
if (reply.Status == IPStatus.Success) {
Console.WriteLine("Antwort von {0} Bytes = {1} Zeit {2}ms TTL = {3}", ip, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl);
success++;
}else
Console.WriteLine("Zeitüberschreitung");
}
if (success > 0) return true;
return false;
}
public static string DNSLookup(string hostNameOrAddress) {
try {
IPHostEntry hostEntry = Dns.GetHostEntry(hostNameOrAddress);

IPAddress[] ips = hostEntry.AddressList;

return string.Join("; ", ips.Select(m => m.ToString()));
} catch (System.Net.Sockets.SocketException) {
return "";
}
}
public static string DNSLookupCustom(string hostNameOrAddress, string DNSServer) {
Resolver resolver = new Resolver();
Stopwatch sw = new Stopwatch();

sw.Start();
Response response = resolver.Query(hostNameOrAddress, QType.A, QClass.IN);
sw.Stop();

if (response.Error != "" || (response.RecordsA.Length == 0 && response.RecordsAAAA.Length == 0)) {
Console.WriteLine(";; " + response.Error);
return "";
} else {
return response.RecordsA[0].ToString();
}
}

public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject {
T foundChild = null;
System.Collections.IEnumerable children = LogicalTreeHelper.GetChildren(parent);
foreach (object child in children) {
if (child is DependencyObject) {
DependencyObject depChild = child as DependencyObject;
if (child is FrameworkElement frameworkElement && frameworkElement.Name.IsEqual(childName)) {
try {
foundChild = (T)child;
} catch {
}
} else
foundChild = FindChild<T>(depChild, childName);
if (foundChild != null) return foundChild;
}
}
return foundChild;
}
}
}
81 changes: 6 additions & 75 deletions BasePlugins/laninfo.cs
@@ -1,5 +1,4 @@
using Heijden.DNS;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -14,7 +13,7 @@
using System.Windows.Shapes;

namespace NIHT.Plugins.Base {
public class laninfo : PluginInterface {
public class LanInfo : NetworkTools, PluginInterface {
#region IPlugin Members
Grid grd;
public string Name {
Expand Down Expand Up @@ -55,9 +54,9 @@ public class laninfo : PluginInterface {
createline(grd, 5, "5 NSLookup DNS Google", "www.google.de", true);
Canvas canv;
IWebProxy proxy = WebRequest.GetSystemWebProxy();
if (proxy.GetProxy(new Uri("http://www.microsoft.com")).Host != "www.microsoft.com") {
createline(grd, 6, "6 Ping Proxyserver", proxy.GetProxy(new Uri("http://www.microsoft.com")).Host, true);
FindChild<TextBox>(grd, "txt_res6").Text = proxy.GetProxy(new Uri("http://www.microsoft.com")).AbsoluteUri;
if (proxy.GetProxy(new Uri("http://www.asfdfasdas.neto")).Host != "www.asfdfasdas.neto") {
createline(grd, 6, "6 Ping Proxyserver", proxy.GetProxy(new Uri("http://www.asfdfasdas.neto")).Host, true);
FindChild<TextBox>(grd, "txt_res6").Text = proxy.GetProxy(new Uri("http://www.asfdfasdas.neto")).AbsoluteUri;
} else {
createline(grd, 6, "6 Ping Proxyserver", "", false);
canv = FindChild<Canvas>(grd, "poi_6");
Expand Down Expand Up @@ -155,7 +154,7 @@ public class laninfo : PluginInterface {
string ip = FindChild<TextBox>(grd, feldname).Text;
if (ip == "")
return "";
else if (pingip(ip))
else if (Ping(ip))
return "green";
else
return "red";
Expand All @@ -178,74 +177,6 @@ public class laninfo : PluginInterface {
};
}

private bool pingip(string ip) {
Ping pingSender = new Ping();
PingOptions options = new PingOptions();

// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;

// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(ip, timeout, buffer, options);
if (reply.Status == IPStatus.Success) {
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
return true;
}
return false;
}
protected string DNSLookup(string hostNameOrAddress) {
try {
IPHostEntry hostEntry = Dns.GetHostEntry(hostNameOrAddress);

IPAddress[] ips = hostEntry.AddressList;

return string.Join("; ", ips.Select(m => m.ToString()));
} catch (System.Net.Sockets.SocketException) {
return "";
}
}
protected string DNSLookupCustom(string hostNameOrAddress, string DNSServer) {
Resolver resolver = new Resolver();
Stopwatch sw = new Stopwatch();

sw.Start();
Response response = resolver.Query(hostNameOrAddress, QType.A, QClass.IN);
sw.Stop();

if (response.Error != "" || (response.RecordsA.Length == 0 && response.RecordsAAAA.Length == 0)) {
Console.WriteLine(";; " + response.Error);
return "";
} else {
return response.RecordsA[0].ToString();
}
}
internal static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject {
T foundChild = null;
System.Collections.IEnumerable children = LogicalTreeHelper.GetChildren(parent);
foreach (object child in children) {
if (child is DependencyObject) {
DependencyObject depChild = child as DependencyObject;
if (child is FrameworkElement frameworkElement && frameworkElement.Name.IsEqual(childName)) {
try {
foundChild = (T)child;
} catch {
}
} else
foundChild = FindChild<T>(depChild, childName);
if (foundChild != null) return foundChild;
}
}
return foundChild;
}

public string Action(int action, object extra) {
throw new NotImplementedException();
}
Expand Down
File renamed without changes.

0 comments on commit 00f540a

Please sign in to comment.