Made some small changes

This commit is contained in:
plane000
2018-05-18 16:51:42 +01:00
parent 717a7c11ea
commit 12d419d921
9 changed files with 152 additions and 90 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Linq;
namespace Networking_Tools {
class CLI_Tools {
public string[] ParseInput(string arr) => arr.ToLower().Split(' ');
public string[] TrimFirst(string[] arr) => arr.Where(w => w != arr[0]).ToArray();
public void PrintArray(string[] arr) {
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i]);
}
}
}
}

View File

@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Networking_Tools {
class DNSTest {
public string HostName { get; set; }
public string[] GetIPs() {
List<string> ipAddresses = new List<string>();
try {
IPHostEntry iphost = Dns.GetHostEntry(HostName);
foreach (IPAddress theAddress in iphost.AddressList) {
if (theAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
ipAddresses.Add(theAddress.ToString());
}
}
} catch (SocketException) {
ipAddresses.Add("");
}
return ipAddresses.ToArray();
}
}
}

View File

@@ -42,11 +42,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DNSTest.cs" />
<Compile Include="CLI Tools.cs" />
<Compile Include="Networking tools\Connectivity Test.cs" />
<Compile Include="Networking tools\DNSTools.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserInterface.cs" />
<Compile Include="WebTools.cs" />
<Compile Include="Networking tools\WebTools.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View File

@@ -0,0 +1,17 @@
using System;
using System.Net.NetworkInformation;
namespace Networking_Tools {
class Connectivity_Test {
public bool checkConnection(string host) {
bool pingable = false;
Ping pinger = new Ping();
try {
PingReply reply = pinger.Send(host);
pingable = reply.Status == IPStatus.Success;
} catch (PingException) { }
return pingable;
}
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
namespace Networking_Tools {
class DNSTest {
private string hostName { get; set; }
private string[] inputArray { get; set; }
private string[] trimmedInputArray { get; set; }
public DNSTest(string[] input, string[] trimmedInput) {
inputArray = input;
trimmedInputArray = trimmedInput;
}
public string[] DNSParser() {
switch (inputArray[0]) {
case "":
break;
}
return new string[0];
}
private string[] GetIPs() {
List<string> ipAddresses = new List<string>();
try {
IPHostEntry iphost = Dns.GetHostEntry(hostName);
foreach (IPAddress theAddress in iphost.AddressList) {
if (theAddress.AddressFamily == AddressFamily.InterNetwork) {
ipAddresses.Add(theAddress.ToString());
}
}
} catch (SocketException) {
ipAddresses.Add("");
}
return ipAddresses.ToArray();
}
private string GetDNSEnd() {
return "";
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
namespace Networking_Tools {
class WebTools {
private string hostName { get; set; }
private string[] inputArray { get; set; }
private string[] trimmedInputArray { get; set; }
public WebTools(string[] input, string[] trimmedInput) {
inputArray = input;
trimmedInputArray = trimmedInput;
}
public string[] WebParser() {
return new string[0];
}
private string ping() {
return "";
}
private string[] redirects() {
return new string[0];
}
}
}

View File

@@ -1,16 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Networking_Tools {
class UserInterface {
private int startWidth;
private int startHeight;
private int startWidth { get; set; }
private int startHeight { get; set; }
public List<string> DNSTools;
public List<string> WebTools;
public void Load() {
DNSTools = new List<string>() {
"getips",
"getdnsend"
};
WebTools = new List<string>() {
"ping",
"redirects"
};
Console.SetCursorPosition(0, 0);
startHeight = Console.WindowHeight;
startWidth = Console.WindowWidth;
@@ -18,18 +30,28 @@ namespace Networking_Tools {
}
public void MainMenu() {
Console.Clear();
Console.WriteLine("Networking Tools by Benjamin Kyd");
Connectivity_Test test = new Connectivity_Test();
while (true) {
Console.Write("> ");
options();
if (test.checkConnection("www.plane000.co.uk")) {
Console.Write("> ");
getInput();
} else {
Console.WriteLine("Connection failed... Attepting to reconnect...");
Thread.Sleep(10000);
MainMenu();
}
}
}
private void options() {
private void getInput() {
CLI_Tools cli = new CLI_Tools();
var input = Console.ReadLine().Trim();
string[] parsed = parseInput(input);
string[] trimmed = trimFirst(parsed);
string[] parsed = cli.ParseInput(input);
string[] trimmed = cli.TrimFirst(parsed);
string[] response = new string[0];
switch (parsed[0]) {
@@ -37,17 +59,18 @@ namespace Networking_Tools {
break;
case "ping":
WebTools ping = new WebTools(parsed, trimmed);
response = ping.WebParser();
break;
case "getdns":
if (parsed.Length > 1) {
DNSTest dns = new DNSTest();
dns.HostName = parsed[1];
response = dns.GetIPs();
} else {
response = new string[1];
response[0] = "No arguments given";
}
DNSTest getDns = new DNSTest(parsed, trimmed);
response = getDns.DNSParser();
break;
case "getdnsendpoint":
DNSTest endPoint = new DNSTest(parsed, trimmed);
response = endPoint.DNSParser();
break;
default:
@@ -55,22 +78,7 @@ namespace Networking_Tools {
break;
}
printArray(response);
}
private string[] parseInput(string arr) {
return arr.ToLower().Split(' ');
}
private string[] trimFirst(string[] arr) {
arr = arr.Where(w => w != arr[0]).ToArray();
return arr;
}
private void printArray(string[] arr) {
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i]);
}
cli.PrintArray(response);
}
}
}

View File

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Networking_Tools {
class WebTools {
public string HostName { get; set; }
public string ping() {
return "";
}
}
}

View File

@@ -77,7 +77,6 @@ namespace Joystick_Controler {
class MouseTranslator {
private bool lastB;
private bool mouseDown;
private int joyX;
@@ -87,15 +86,9 @@ namespace Joystick_Controler {
joyX = x;
joyY = y;
if (b != lastB && mouseDown) {
clickUp();
} else if (b == lastB && mouseDown) {
} else if (b != lastB && !mouseDown) {
clickDown();
}
moveMouse();
lastB = b;
}
private void moveMouse() {