-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
230 lines (195 loc) · 7.19 KB
/
Main.cs
File metadata and controls
230 lines (195 loc) · 7.19 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
using CefSharp;
using CefSharp.WinForms;
using System;
using System.IO;
using System.Windows.Forms;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace LoadRandom
{
public partial class Main : Form
{
private URLLoader childForm;
private string[] proxyList;
private int proxyIndex = 0;
private int count = 0;
private Timer proxyChangeTimer;
public Main()
{
InitializeComponent();
LoadProxyListAsync();
}
private async Task LoadProxyListAsync()
{
string url_http = "https://raw.githubusercontent.com/mmpx12/proxy-list/refs/heads/master/http.txt";
string debugDirectory_http = AppDomain.CurrentDomain.BaseDirectory;
string filePath_http = Path.Combine(debugDirectory_http, "http.txt");
string url_https = "https://raw.githubusercontent.com/mmpx12/proxy-list/refs/heads/master/https.txt";
string debugDirectory_https = AppDomain.CurrentDomain.BaseDirectory;
string filePath_https = Path.Combine(debugDirectory_https, "http.txt");
using (HttpClient client = new HttpClient())
{
try
{
var response = await client.GetAsync(url_http);
response.EnsureSuccessStatusCode();
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes(filePath_http, fileBytes);
response = await client.GetAsync(url_https);
response.EnsureSuccessStatusCode();
fileBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes(filePath_https, fileBytes);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
List<string> combinedProxyList = new List<string>();
try
{
if (File.Exists("http.txt"))
{
string[] proxyList1 = File.ReadAllLines("http.txt");
combinedProxyList.AddRange(proxyList1);
}
if (File.Exists("https.txt"))
{
string[] proxyList2 = File.ReadAllLines("https.txt");
combinedProxyList.AddRange(proxyList2);
}
// Shuffle the combined list
Random rng = new Random();
int n = combinedProxyList.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
string value = combinedProxyList[k];
combinedProxyList[k] = combinedProxyList[n];
combinedProxyList[n] = value;
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading proxy lists: " + ex.Message);
}
try
{
proxyList = combinedProxyList.ToArray();
if (proxyList.Length<1)
proxyList = File.ReadAllLines("temp.txt");
Proxy_ProgressBar.Minimum = 0;
Proxy_ProgressBar.Maximum = proxyList.Length;
Proxy_ProgressBar.Value = 0;
}
catch (Exception ex)
{
MessageBox.Show("Error loading proxy list: " + ex.Message);
}
}
private void StartProxyChangeTimer()
{
proxyChangeTimer = new Timer();
proxyChangeTimer.Interval = int.Parse(Duration_TextBox.Text)*1000;
proxyChangeTimer.Tick += ProxyChangeTimer_Tick;
proxyChangeTimer.Start();
}
private void ProxyChangeTimer_Tick(object sender, EventArgs e)
{
if (proxyIndex >= proxyList.Length)
{
proxyIndex = 0;
}
MainAsync();
}
private void ChangeProxy(string proxyAddress)
{
ChromiumWebBrowser chromeBrowser=new ChromiumWebBrowser();
Cef.Shutdown();
CefSettings settings = new CefSettings();
settings.CefCommandLineArgs.Add("proxy-server", "https://" + proxyAddress);
Cef.Initialize(settings);
chromeBrowser.Load(chromeBrowser.Address);
}
private string GetCurrentProxy()
{
if(proxyIndex> proxyList.Length)
{
proxyIndex = 0;
}
string str = proxyList[proxyIndex];
proxyIndex++;
return str;
}
private void Run_Button_Click(object sender, EventArgs e)
{
Stop_Button.Enabled = true;
Run_Button.Enabled = false;
try
{
string urlstr = URL_TextBox.Text;
MainAsync();
StartProxyChangeTimer();
}
catch (UriFormatException ex)
{
MessageBox.Show("Invalid URL format: " + ex.Message);
}
}
public async Task MainAsync()
{
for (int i = 0; i < int.Parse(URLCount_TextBox.Text); ) {
Proxy_ProgressBar.Value = proxyIndex;
Run_label.Text = proxyIndex.ToString();
string prx = GetCurrentProxy();
var proxy = new WebProxy(prx);
var httpClientHandler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
using (HttpClient client = new HttpClient(httpClientHandler))
{
try
{
var response = await client.GetAsync("https://taleblou.ir/");
if (response.IsSuccessStatusCode)
{
childForm = new URLLoader(URL_TextBox.Text, prx, int.Parse(Duration_TextBox.Text));
// childForm3.c = c3;
childForm.Show();
count++;
Success_label.Text = count.ToString();
i++;
}
else
{
Console.WriteLine($"Proxy failed with status code: {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
}
private void Stop_Button_Click(object sender, EventArgs e)
{
Run_label.Text = "0";
Success_label.Text = "0";
proxyIndex = 0;
proxyChangeTimer.Stop();
Proxy_ProgressBar.Value = 0;
Stop_Button.Enabled=false;
Run_Button.Enabled=true;
}
}
}