Skip to content

Commit 5d42797

Browse files
author
miticyber
committed
Add project files.
1 parent a4253a7 commit 5d42797

5 files changed

+227
-0
lines changed

FileWorker.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ProxyFinderAndChecker
8+
{
9+
public class FileWorker
10+
{
11+
public static string[] ReadFile(string path)
12+
{
13+
return File.ReadAllLines(path);
14+
}
15+
public static void WriteFile(string text, string path)
16+
{
17+
if(!File.Exists(path)) File.Create(path);
18+
using (StreamWriter writer = new StreamWriter(path,true))
19+
{
20+
writer.WriteLine(text);
21+
};
22+
}
23+
}
24+
}

Logger.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Spectre.Console;
2+
3+
namespace ProxyFinderAndChecker
4+
{
5+
public static class Logger
6+
{
7+
public static void Log(string text, Color color)
8+
{
9+
AnsiConsole.Foreground = Color.Orange1;
10+
AnsiConsole.Write("LOG : ");
11+
AnsiConsole.Foreground = color;
12+
AnsiConsole.WriteLine(text);
13+
14+
}
15+
16+
public static void Note(Color color,params string[] notes)
17+
{
18+
Console.WriteLine("");
19+
string sep = "";
20+
for (int i = 0; i < (notes.First().Length + notes[^1].Length) + 10; i++) sep += "=";
21+
22+
SepWriter(sep);
23+
24+
AnsiConsole.Foreground = color;
25+
foreach(string note in notes)
26+
{
27+
Console.SetCursorPosition((Console.WindowWidth - note.Length) / 2, Console.CursorTop);
28+
AnsiConsole.WriteLine(note);
29+
}
30+
31+
SepWriter(sep);
32+
33+
Console.ResetColor();
34+
Console.SetCursorPosition(0, Console.CursorTop);
35+
36+
}
37+
38+
39+
private static void SepWriter(string sep)
40+
{
41+
Console.SetCursorPosition((Console.WindowWidth - sep.Length) / 2, Console.CursorTop);
42+
AnsiConsole.Foreground = Color.DarkCyan;
43+
AnsiConsole.WriteLine(sep);
44+
}
45+
46+
47+
}
48+
}

Program.cs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using ProxyFinderAndChecker;
2+
using Spectre.Console;
3+
using System.Net;
4+
using System.Text.Json;
5+
6+
#region ProxyFiles
7+
8+
string RunTimePath = Environment.CurrentDirectory;
9+
string ProxyFolder = Path.Combine(RunTimePath, "Proxies");
10+
string CheckedPath = Path.Combine(ProxyFolder, "CheckedProxy");
11+
if (!Directory.Exists(ProxyFolder)) Directory.CreateDirectory(ProxyFolder);
12+
if (!Directory.Exists(CheckedPath)) Directory.CreateDirectory(CheckedPath);
13+
var ProxyListFiles = new List<string>();
14+
var files = Directory.GetFiles(ProxyFolder, "*.txt");
15+
foreach (var file in files)
16+
{
17+
ProxyListFiles.Add(file.Split("Proxies")[1].Substring(1));
18+
}
19+
20+
#endregion
21+
22+
#region About
23+
24+
Console.ForegroundColor = ConsoleColor.Cyan;
25+
Console.WriteLine(@" ____ ________ __
26+
/ __ \_________ _ ____ __ / ____/ /_ ___ _____/ /_____ _____
27+
/ /_/ / ___/ __ \| |/_/ / / / / / / __ \/ _ \/ ___/ //_/ _ \/ ___/
28+
/ ____/ / / /_/ /> </ /_/ / / /___/ / / / __/ /__/ ,< / __/ /
29+
/_/ /_/ \____/_/|_|\__, / \____/_/ /_/\___/\___/_/|_|\___/_/
30+
/____/ ");
31+
32+
Logger.Note(Color.Purple, "Coded By : MohmmadMahdi Khoubrouy", "Github : https://github.com/miticyber", "If you like it, please star the project on GitHub");
33+
34+
35+
#endregion
36+
37+
38+
#region Check Exists Proxy file in directory
39+
if (ProxyListFiles.Count() <= 0)
40+
{
41+
Logger.Log("ProxyList File Not Found In Folder Proxies", Color.Red);
42+
Logger.Note(Color.Cyan1, "For Working this app please first create ProxyList and Copy to Proxies Folder and then Run app");
43+
Logger.Note(Color.Khaki1, "Press enter for exit...");
44+
Console.ReadKey();
45+
}
46+
#endregion
47+
48+
#region main
49+
else
50+
{
51+
Console.WriteLine("");
52+
var selectedFile = AnsiConsole.Prompt(
53+
new SelectionPrompt<string>()
54+
.Title("What's your [green]ProxyList file[/]?")
55+
.PageSize(10)
56+
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
57+
.AddChoices(ProxyListFiles));
58+
59+
var readFile = FileWorker.ReadFile(Path.Combine(ProxyFolder, selectedFile));
60+
61+
Logger.Log($"{readFile.Count()} Proxy Found !", Color.Green);
62+
63+
Console.WriteLine("");
64+
var SelectedProxyType = AnsiConsole.Prompt(
65+
new SelectionPrompt<string>()
66+
.Title("What's your [blue]ProxyList Type[/]?")
67+
.PageSize(10)
68+
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
69+
.AddChoices(new[]
70+
{
71+
"http","socks4","socks5"
72+
}));
73+
74+
int success = 0;
75+
int failed = 0;
76+
foreach (var prox in readFile)
77+
{
78+
string port = prox.Split(":")[01];
79+
try
80+
{
81+
var proxy = new Proxy();
82+
string res = proxy.CheckProxy(new WebProxy($"{SelectedProxyType}://{prox}"));
83+
if (!string.IsNullOrEmpty(res))
84+
{
85+
var json = JsonSerializer.Deserialize<CheckedProxyData>(res);
86+
string data = $"{json.query}:{port},{json.country}";
87+
FileWorker.WriteFile(data, Path.Combine(CheckedPath, selectedFile));
88+
Logger.Log("Check Success : " + data, Color.Green);
89+
success++;
90+
}
91+
}
92+
catch
93+
{
94+
failed++;
95+
Logger.Log("Check Failed : " + prox, Color.Red);
96+
}
97+
}
98+
99+
Logger.Note(Color.Aqua, "All proxies were checked ..", "Press enter to exit");
100+
Console.ReadKey();
101+
}
102+
#endregion

Proxy.cs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Net;
2+
3+
namespace ProxyFinderAndChecker
4+
{
5+
public class Proxy
6+
{
7+
8+
public string CheckProxy(WebProxy proxy)
9+
{
10+
string data = "";
11+
using (var client = new HttpClient(handler: new HttpClientHandler() { Proxy = proxy }))
12+
{
13+
client.Timeout = TimeSpan.FromSeconds(5);
14+
data = client.GetStringAsync("http://ip-api.com/json").GetAwaiter().GetResult();
15+
}
16+
return data;
17+
}
18+
}
19+
20+
21+
public class CheckedProxyData
22+
{
23+
public string status { get; set; }
24+
public string country { get; set; }
25+
public string countryCode { get; set; }
26+
public string region { get; set; }
27+
public string regionName { get; set; }
28+
public string city { get; set; }
29+
public string zip { get; set; }
30+
public double lat { get; set; }
31+
public double lon { get; set; }
32+
public string timezone { get; set; }
33+
public string isp { get; set; }
34+
public string org { get; set; }
35+
public string @as { get; set; }
36+
public string query { get; set; }
37+
}
38+
}

ProxyFinderAndChecker.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="RestSharp" Version="108.0.1" />
12+
<PackageReference Include="Spectre.Console" Version="0.44.0" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)