Skip to content

Commit

Permalink
Add Multi Thread Check & Add Section Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
miticyber committed Sep 3, 2022
1 parent 02748c9 commit 7c80f8c
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 73 deletions.
28 changes: 17 additions & 11 deletions FileWorker.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProxyFinderAndChecker
namespace ProxyFinderAndChecker
{
public class FileWorker
{
static readonly object _ThreadLock = new object();

public static string[] ReadFile(string path)
{
return File.ReadAllLines(path);
}
public static void WriteFile(string text, string path)
{
if(!File.Exists(path)) File.Create(path);
using (StreamWriter writer = new StreamWriter(path,true))
lock (_ThreadLock)
{
writer.WriteLine(text);
};
try
{
if (!File.Exists(path)) File.Create(path).Close();
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine(text);
};
}
catch
{

}
}
}
}
}
6 changes: 3 additions & 3 deletions Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public static void Log(string text, Color color)

}

public static void Note(Color color,params string[] notes)
public static void Note(Color color, params string[] notes)
{
AnsiConsole.WriteLine("");

AnsiConsole.Foreground = color;
foreach(string note in notes)
foreach (string note in notes)
{
AnsiConsole.WriteLine("- "+note);
AnsiConsole.WriteLine("- " + note);
}

AnsiConsole.WriteLine("");
Expand Down
191 changes: 139 additions & 52 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using ProxyFinderAndChecker;
using ProxyChecker.ProxyService;
using ProxyChecker.Settings;
using ProxyFinderAndChecker;
using Spectre.Console;
using System.Net;
using System.Text.Json;

#region ProxyFiles
using System.Diagnostics;
#region Configurations

string RunTimePath = Environment.CurrentDirectory;
string ProxyFolder = Path.Combine(RunTimePath, "Proxies");
string CheckedPath = Path.Combine(ProxyFolder, "CheckedProxy");
if (!Directory.Exists(ProxyFolder)) Directory.CreateDirectory(ProxyFolder);
if (!Directory.Exists(CheckedPath)) Directory.CreateDirectory(CheckedPath);
SettingFileConfigure.CreateSettingFile();
var ProxyListFiles = new List<string>();
var files = Directory.GetFiles(ProxyFolder, "*.txt");
foreach (var file in files)
Expand All @@ -33,70 +34,156 @@
Logger.Note(Color.Purple, "Coded By : MohmmadMahdi Khoubrouy", "Github : https://github.com/miticyber", "If you like it, please star the project on GitHub");


#endregion
Logger.Note(Color.Orange1, $"Current Timeout Value : {SettingFileConfigure.GetTimeOut()} Seconds ", $"Current BotThread Value : {SettingFileConfigure.GetBotThread()}");

#region Check Exists Proxy file in directory
if (ProxyListFiles.Count() <= 0)
{
Logger.Log("ProxyList File Not Found In Folder Proxies", Color.Red);
Logger.Note(Color.Cyan1, "For Working this app please first create ProxyList", "Copy to Proxies Folder and then Run app");
Logger.Note(Color.Khaki1, "Press enter for exit...");
Console.ReadKey();
}
#endregion

#region main
else
{
Console.WriteLine("");
var selectedFile = AnsiConsole.Prompt(

#region Main Menu

var SectionSelected = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What's your [green]ProxyList file[/]?")
.Title("[green]Please select the section you want :backhand_index_pointing_down:[/]")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoices(ProxyListFiles));
.HighlightStyle(Style.Plain.Foreground(Color.Red3_1))
.MoreChoicesText("[grey](Move up and down to reveal more Section)[/]")
.AddChoices(new[] {
"Proxy Checker","Setting","Exit"
})); ;



if (SectionSelected == "Proxy Checker")
{
#region Proxy Section
if (ProxyListFiles.Count() <= 0)
{
Logger.Log("ProxyList File Not Found In Folder Proxies", Color.Red);
Logger.Note(Color.Cyan1, "For Working this app please first create ProxyList", "Copy to Proxies Folder and then Run app");
Logger.Note(Color.Khaki1, "Press enter for exit...");
Console.ReadKey();
}
else
{
Console.WriteLine("");
var selectedFile = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What's your [green]ProxyList file[/]?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoices(ProxyListFiles));

var readFile = FileWorker.ReadFile(Path.Combine(ProxyFolder, selectedFile));
var readFile = FileWorker.ReadFile(Path.Combine(ProxyFolder, selectedFile));

Logger.Log($"{readFile.Count()} Proxy Found !", Color.Green);
Logger.Log($"{readFile.Count()} Proxy Found !", Color.Green);

Console.WriteLine("");
var SelectedProxyType = AnsiConsole.Prompt(
Console.WriteLine("");
var SelectedProxyType = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What's your [blue]ProxyList Type[/]?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoices(new[]
{
"http","socks4","socks5"
}));




var ProxyCheckerService = new CheckerService();
ProxyCheckerService.StartCheckProxyService(SettingFileConfigure.GetBotThread(), readFile, SelectedProxyType,
new RegistrarSetting()
.SetGoodPath(Path.Combine(CheckedPath, selectedFile)));

while (true)
{
Thread.Sleep(1000);
if (ProxyCheckerService.GetThreadAlive() <= 0)
{
Logger.Note(Color.Aqua, "All proxies were checked ..", $"Good = {ProxyCheckerService.GetGoodCount()} ", $"Bad = {ProxyCheckerService.GetBadCount()}", "Press enter to exit");
Console.ReadKey();
break;
}
}

}
#endregion
}
else if (SectionSelected == "Setting")
{
#region Setting Section
var SettingItem = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What's your [blue]ProxyList Type[/]?")
.Title("[green]Please select the section you want [/]")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoices(new[]
.HighlightStyle(Style.Plain.Foreground(Color.Red3_1))
.MoreChoicesText("[grey](Move up and down to reveal more Section)[/]")
.AddChoices(new[] {
"BotThread","TimeOut","Exit"
})); ;


if (SettingItem == "BotThread")
{
#region BotThread Section
Logger.Note(Color.Aqua, $"Current BotThread value: {SettingFileConfigure.GetBotThread()}");
var BotThreadNumber = AnsiConsole.Ask<int>(" [royalblue1]What is your desired new[/] [red]number[/] for [green]Bot Thread[/] ?");
if (BotThreadNumber > 0)
{
"http","socks4","socks5"
}));
SettingFileConfigure.SetBotThread(BotThreadNumber);

int success = 0;
int failed = 0;
foreach (var prox in readFile)
AnsiConsole.MarkupLine("[italic]The new value was [green]successfully[/] set[/]");
}
else
{
AnsiConsole.MarkupLine("[bold][red]Input cannot be less than zero or zero[/][/]");
AnsiConsole.MarkupLine("[italic]The new value was [red]failed[/] set[/]");
}

#endregion
}
else if (SettingItem == "TimeOut")
{
string port = prox.Split(":")[01];
try
Logger.Note(Color.Aqua, $"Current TimeOut value: {SettingFileConfigure.GetTimeOut()}");
var TimeOutValue = AnsiConsole.Ask<int>(" [bold][green]What is the amount of[/] [red]timeout[/] [green]based on[/] [red]seconds[/] [/] ?");

if (TimeOutValue > 0)
{
var proxy = new Proxy();
string res = proxy.CheckProxy(new WebProxy($"{SelectedProxyType}://{prox}"));
if (!string.IsNullOrEmpty(res))
{
var json = JsonSerializer.Deserialize<CheckedProxyData>(res);
string data = $"{json.query}:{port},{json.country}";
FileWorker.WriteFile(data, Path.Combine(CheckedPath, selectedFile));
Logger.Log("Check Success : " + data, Color.Green);
success++;
}
SettingFileConfigure.SetTimeOut(TimeOutValue);

AnsiConsole.MarkupLine("[italic]The new value was [green]successfully[/] set[/]");
}
catch
else
{
failed++;
Logger.Log("Check Failed : " + prox, Color.Red);
AnsiConsole.MarkupLine("[bold][red]Input cannot be less than zero or zero[/][/]");
AnsiConsole.MarkupLine("[italic]The new value was [red]failed[/] set[/]");
}
}
else if (SettingItem == "Exit")
{
#region Exit Section
AnsiConsole.MarkupLine("[italic][aqua] Ok GoodBye .. [/][/]");
Thread.Sleep(1500);
Environment.Exit(0);
#endregion
}

Logger.Note(Color.Aqua, "All proxies were checked ..", "Press enter to exit");
Console.ReadKey();

#endregion
}
else if (SectionSelected == "Exit")
{
#region Exit Section
AnsiConsole.MarkupLine("[italic][aqua] Ok GoodBye .. [/][/]");
Thread.Sleep(1500);
Environment.Exit(0);
#endregion
}
#endregion

#endregion




Console.ReadKey();
20 changes: 14 additions & 6 deletions Proxy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using ProxyChecker.Settings;
using System.Net;

namespace ProxyFinderAndChecker
{
Expand All @@ -7,13 +8,20 @@ public class Proxy

public string CheckProxy(WebProxy proxy)
{
string data = "";
using (var client = new HttpClient(handler: new HttpClientHandler() { Proxy = proxy }))
try
{
client.Timeout = TimeSpan.FromSeconds(5);
data = client.GetStringAsync("http://ip-api.com/json").GetAwaiter().GetResult();
var data = "";
using (var client = new HttpClient(handler: new HttpClientHandler() { Proxy = proxy }))
{
client.Timeout = TimeSpan.FromSeconds(SettingFileConfigure.GetTimeOut());
data = client.GetStringAsync("http://ip-api.com/json").GetAwaiter().GetResult();
}
return data;
}
catch
{
return "Error";
}
return data;
}
}

Expand Down
1 change: 0 additions & 1 deletion ProxyChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RestSharp" Version="108.0.1" />
<PackageReference Include="Spectre.Console" Version="0.44.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 7c80f8c

Please sign in to comment.