-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
497 lines (479 loc) · 24.4 KB
/
Program.cs
File metadata and controls
497 lines (479 loc) · 24.4 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace ProxyPooler
{
internal class Program
{
public static readonly object consoleLock = new object();
private static int FoundAlive = 0;
private static int Checked = 0;
private static int TotalProxies = 0;
private static dynamic ipData = null;
private static string confirmLink = "https://www.howsmyssl.com/";
private static int timeOut = 5000;
private static readonly HttpClient client = new HttpClient { Timeout = TimeSpan.FromMilliseconds(timeOut) };
private static string exeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
private static string dir = Path.Combine(exeDir ?? ".", "FoundAlive.txt");
private static int retries = 1;
private static int delayMs = 0;
private static int threadCount = 1000;
private static double rate = 0;
// TODO:
// 1. If you start once and then try to go again in the same sesion the rate proxies/sec will stay at 0.0/not be calculated
private static async Task Main()
{
Menu();
}
private static async Task Menu()
{
Colorful.Console.Clear();
FoundAlive = 0;
Checked = 0;
TotalProxies = 0;
ipData = null;
Colorful.Console.Title = "Safeguarding your virtual vessel is the key to a secure voyage.";
Logo();
Colorful.Console.WriteLine("\n" + Center("[1]: Start Scan (FAST)"), Color.White);
Colorful.Console.WriteLine(Center("[2]: Start Scan (STRICT)"), Color.White);
Colorful.Console.WriteLine(Center("[3]: Settings"), Color.White);
Colorful.Console.WriteLine(Center("[4]: Discord"), Color.White);
Colorful.Console.WriteLine(Center("[5]: Exit"), Color.White);
Colorful.Console.Write("\n" + Center("--> "), Color.White);
string input = Colorful.Console.ReadLine();
if (input == "1")
{
Colorful.Console.Clear();
Logo();
StartTitleUpdate();
await StartScan(Memory.links, "FAST");
Colorful.Console.ReadKey();
Environment.Exit(0);
}
if (input == "2")
{
Colorful.Console.Clear();
Logo();
StartTitleUpdate();
await StartScan(Memory.links, "STRICT");
Colorful.Console.ReadKey();
Environment.Exit(0);
}
if (input == "3")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[1]: Amount of Threads to use = {threadCount}"), Color.White);
Colorful.Console.WriteLine(Center($"[2]: Link to Confirm Alive Proxies = {confirmLink}"), Color.White);
Colorful.Console.WriteLine(Center($"[3]: Timeout before Dead Proxies are Confirmed = {timeOut}ms"), Color.White);
Colorful.Console.WriteLine(Center($"[4]: Amount of Retries to check if each proxy is Alive or Dead = {retries}"), Color.White);
Colorful.Console.WriteLine(Center($"[5]: Delay before rechecking the same proxy and or moving on to another = {delayMs}ms"), Color.White);
Colorful.Console.WriteLine(Center("[6]: Go Back"), Color.White);
Colorful.Console.Write("\n" + Center("--> "), Color.White);
string input2 = Colorful.Console.ReadLine();
if (input2 == "1")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[CURRENT]: Amount of Threads to use = {threadCount}"), Color.White);
Colorful.Console.Write(Center("[NEW]: Amount of Threads to use = "), Color.White);
threadCount = Convert.ToInt32(Colorful.Console.ReadLine());
await Menu();
}
if (input2 == "2")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[CURRENT]: Link to Confirm Alive Proxies = {confirmLink}"), Color.White);
Colorful.Console.Write(Center($"[NEW]: Link to Confirm Alive Proxies = "), Color.White);
confirmLink = Colorful.Console.ReadLine();
await Menu();
}
if (input2 == "3")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[CURRENT]: Timeout before Dead Proxies are Confirmed = {timeOut}ms"), Color.White);
Colorful.Console.Write(Center("[NEW]: Timeout before Dead Proxies are Confirmed = "), Color.White);
timeOut = Convert.ToInt32(Colorful.Console.ReadLine());
await Menu();
}
if (input2 == "4")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[CURRENT]: Amount of Retries to check if each proxy is Alive or Dead = {retries}"), Color.White);
Colorful.Console.Write(Center("[NEW]: Amount of Retries to check if each proxy is Alive or Dead = "), Color.White);
retries = Convert.ToInt32(Colorful.Console.ReadLine());
await Menu();
}
if (input2 == "5")
{
Colorful.Console.Clear();
Logo();
Colorful.Console.WriteLine("\n" + Center($"[CURRENT]: Delay before rechecking the same proxy and or moving on to another = {delayMs}ms"), Color.White);
Colorful.Console.Write(Center("[NEW]: Delay before rechecking the same proxy and or moving on to another = "), Color.White);
delayMs = Convert.ToInt32(Colorful.Console.ReadLine());
await Menu();
}
if (input2 != "6")
{
await Menu();
}
else
{
await Menu();
}
}
if (input == "4")
{
System.Diagnostics.Process.Start("https://discord.gg/bMT4CFmPmH");
await Menu();
}
if (input == "5")
{
Environment.Exit(0);
}
else
{
await Menu();
}
}
private static async Task StartScan(string[] links, string scanType)
{
Stopwatch stopwatch = Stopwatch.StartNew();
// Collect all unique proxies
ConcurrentDictionary<string, byte> uniqueProxies = new ConcurrentDictionary<string, byte>();
List<Task> scrapeTasks = new List<Task>();
foreach (string link in links)
{
scrapeTasks.Add(Task.Run(async () =>
{
try
{
string content = await client.GetStringAsync(link);
MatchCollection matches = Regex.Matches(content, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{2,5}");
foreach (Match match in matches)
{
uniqueProxies.TryAdd(match.Value, 0);
}
}
catch (HttpRequestException)
{
lock (consoleLock)
{
Colorful.Console.WriteLine($"[DEAD LINK]> {link}", Color.Red);
}
}
catch (Exception ex)
{
lock (consoleLock)
{
Colorful.Console.WriteLine($"[ERROR]> {link}: {ex.Message}", Color.Red);
}
}
}));
}
await Task.WhenAll(scrapeTasks);
TotalProxies = uniqueProxies.Count;
// Split proxies into batches based on threadCount
string[] proxies = uniqueProxies.Keys.ToArray();
int batchSize = (int)Math.Ceiling((double)proxies.Length / threadCount);
List<Task> checkTasks = new List<Task>();
List<string>[] batches = new List<string>[threadCount];
// Initialize batches
for (int i = 0; i < threadCount; i++)
{
batches[i] = new List<string>();
}
// Distribute proxies into batches
for (int i = 0; i < proxies.Length; i++)
{
int batchIndex = i / batchSize;
if (batchIndex < threadCount) // Ensure we don't exceed array bounds
{
batches[batchIndex].Add(proxies[i]);
}
}
// Initialize rate calculation variables
int lastCheckedCount = 0;
DateTime lastUpdate = DateTime.UtcNow;
object rateLock = new object();
// Buffer for file output
ConcurrentBag<string> fileBuffer = new ConcurrentBag<string>();
// Rate updater task
Task rateUpdater = Task.Run(async () =>
{
while (!checkTasks.All(t => t.IsCompleted))
{
await Task.Delay(1000);
lock (rateLock)
{
int currentChecked = Checked;
double elapsedSeconds = (DateTime.UtcNow - lastUpdate).TotalSeconds;
if (elapsedSeconds > 0)
{
double newRate = (currentChecked - lastCheckedCount) / elapsedSeconds;
rate = newRate;
lastCheckedCount = currentChecked;
lastUpdate = DateTime.UtcNow;
}
}
}
});
// Process each batch in a separate task
foreach (var batch in batches)
{
if (batch.Count > 0) // Only process non-empty batches
{
checkTasks.Add(Task.Run(async () =>
{
foreach (string proxy in batch)
{
bool isAlive = await CheckFast(proxy);
if (scanType == "FAST") { isAlive = await CheckFast(proxy); }
if (scanType == "STRICT") { isAlive = await CheckStrict(proxy); }
Interlocked.Increment(ref Checked);
if (isAlive)
{
string[] array = proxy.Split(':');
if (array.Length < 2)
{
lock (consoleLock)
{
Colorful.Console.WriteLine($"[ERROR]> Invalid proxy format: {proxy}", Color.Red);
}
continue;
}
string url = null; // REDACTED
JToken localIpData = await ParseLink($"{url}{array[0]}?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query");
Interlocked.Increment(ref FoundAlive);
fileBuffer.Add(proxy + "\n");
string dbType = "ALIVE";
if (localIpData != null && localIpData["status"] != null && localIpData["status"].ToString() != "noInternet")
{
bool isProxy = localIpData["proxy"]?.ToString().Contains("False") ?? false;
bool isHosting = localIpData["hosting"]?.ToString().Contains("False") ?? false;
if (isProxy && isHosting)
{
dbType = localIpData["mobile"]?.ToString().Contains("True") ?? false ? "MOBILE" : "HQ";
lock (consoleLock)
{
Colorful.Console.Write(" [", Color.White);
Colorful.Console.Write("FOUND", Color.LimeGreen);
Colorful.Console.Write(dbType == "MOBILE" ? " MOBILE" : " HQ", Color.Lime);
Colorful.Console.Write("]", Color.White);
Colorful.Console.Write("> ", Color.Gray);
Colorful.Console.WriteWithGradient(proxy, Color.Red, Color.White, 10);
Colorful.Console.Write(" in ", Color.LightGray);
Colorful.Console.Write($"{localIpData["city"] ?? "[RateLimited]"}, {localIpData["country"] ?? "[RateLimited]"} ({localIpData["countryCode"] ?? "[RateLimited]"})", Color.White);
Colorful.Console.Write(" by ", Color.LightGray);
Colorful.Console.Write($"{localIpData["isp"] ?? "[RateLimited]"}\n", Color.White);
}
}
else
{
lock (consoleLock)
{
Colorful.Console.Write(" [", Color.White);
Colorful.Console.Write("FOUND", Color.LimeGreen);
Colorful.Console.Write("]", Color.White);
Colorful.Console.Write("> ", Color.Gray);
Colorful.Console.WriteWithGradient(proxy, Color.Red, Color.White, 10);
Colorful.Console.Write(" in ", Color.LightGray);
Colorful.Console.Write($"{localIpData["city"] ?? "[RateLimited]"}, {localIpData["country"] ?? "[RateLimited]"} ({localIpData["countryCode"] ?? "[RateLimited]"})", Color.White);
Colorful.Console.Write(" by ", Color.LightGray);
Colorful.Console.Write($"{localIpData["isp"] ?? "[RateLimited]"}\n", Color.White);
}
}
}
else
{
lock (consoleLock)
{
Colorful.Console.Write(" [", Color.White);
Colorful.Console.Write("FOUND", Color.LimeGreen);
Colorful.Console.Write("]", Color.White);
Colorful.Console.Write("> ", Color.Gray);
Colorful.Console.WriteWithGradient(proxy, Color.Red, Color.White, 10);
Colorful.Console.Write(" in ", Color.LightGray);
Colorful.Console.Write($"[RateLimited]", Color.White);
Colorful.Console.Write(" by ", Color.LightGray);
Colorful.Console.Write($"[RateLimited]\n", Color.White);
}
}
}
}
}));
}
}
await Task.WhenAll(checkTasks);
await rateUpdater;
// Write buffered file output
File.AppendAllText(dir, string.Concat(fileBuffer));
stopwatch.Stop();
lock (consoleLock)
{
Colorful.Console.WriteLine($" Scan completed in {stopwatch.Elapsed}s!", Color.White);
}
await Task.Delay(3000);
await Menu();
}
private static async Task<bool> CheckStrict(string proxy) // New Strict Method using the old method but then also checking the confirmLink for a 200 code!!
{
string[] proxyParts = proxy.Split(':');
if (proxyParts.Length < 2)
{
return false; // Invalid proxy format
}
string proxyIp = proxyParts[0];
for (int attempt = 1; attempt <= retries; attempt++)
{
var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxy),
UseProxy = true
};
using (var checkClient = new HttpClient(handler) { Timeout = TimeSpan.FromMilliseconds(timeOut) })
{
try
{
// First check: Verify proxy IP
string url = null; // REDACTED
string jsonResponse = await checkClient.GetStringAsync(url).ConfigureAwait(false);
var jsonObject = JToken.Parse(jsonResponse);
string publicIp = jsonObject["ip"]?.ToString();
if (!string.IsNullOrEmpty(publicIp) && publicIp == proxyIp)
{
// Second check: Verify connection to confirmLink with 200 status
await Task.Delay(delayMs).ConfigureAwait(false);
try
{
var response = await checkClient.GetAsync(confirmLink).ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return true; // Proxy IP matches and confirmLink returns 200
}
}
catch
{
// Failed to connect to confirmLink
if (attempt == retries)
{
return false; // All retries failed for confirmLink
}
}
}
}
catch
{
if (attempt == retries)
{
return false; // All retries failed for IP check
}
}
await Task.Delay(delayMs).ConfigureAwait(false);
}
}
return false;
}
private static async Task<bool> CheckFast(string proxy) // New Fast Method checking the confirmLink(https://www.howsmyssl.com/) for a 200 code!!
{
string[] proxyParts = proxy.Split(':');
if (proxyParts.Length < 2)
{
return false; // Invalid proxy format
}
for (int attempt = 1; attempt <= retries; attempt++)
{
var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxy),
UseProxy = true
};
using (var checkClient = new HttpClient(handler) { Timeout = TimeSpan.FromMilliseconds(timeOut) })
{
try
{
// First check: Verify connection to confirmLink with 200 status
await Task.Delay(delayMs).ConfigureAwait(false);
try
{
var response = await checkClient.GetAsync(confirmLink).ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return true; // confirmLink returns 200
}
}
catch
{
// Failed to connect to confirmLink
if (attempt == retries)
{
return false; // All retries failed for confirmLink
}
}
}
catch
{
if (attempt == retries)
{
return false; // All retries failed for IP check
}
}
await Task.Delay(delayMs).ConfigureAwait(false);
}
}
return false;
}
private static async Task<JToken> ParseLink(string link)
{
try
{
string jsonText = await client.GetStringAsync(link);
return JToken.Parse(jsonText);
}
catch
{
return JToken.Parse("{\"status\":\"noInternet\"}");
}
}
public static void Logo()
{
lock (consoleLock)
{
Colorful.Console.WriteWithGradient("\r\n\r\n | | | | \r\n | ,---.,---.,---.|,---.|--- ' ,---. \r\n | | || || ||| || `---. \r\n `---'`---'` '`---|`` '`---' `---' \r\n `---' \r\n ,---. ,---. | | \r\n |---',---.,---.. ,, .| _.,---.,---.|---.|---.,---.,---.\r\n | | | | >< | || || ,---|| || ||---'| \r\n ` ` `---'' ``---|`---'` `---^`---'`---'`---'` v2.0 \r\n `---' \n", Color.Red, Color.White, 5);
}
}
private static string Center(string text)
{
int count = (Colorful.Console.WindowWidth - text.Length) / 2;
return new string(' ', count) + text;
}
private static void StartTitleUpdate()
{
Task.Run(async () =>
{
while (true)
{
lock (consoleLock)
{
Colorful.Console.Title = $"You have checked {Checked}/{TotalProxies} proxies and found {FoundAlive} alive at a speed of {rate:F1} proxies/sec!";
}
await Task.Delay(100);
}
});
}
}
}