-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
267 lines (243 loc) · 10.2 KB
/
index.js
File metadata and controls
267 lines (243 loc) · 10.2 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
import axios from 'axios';
import * as fs from 'fs/promises';
import * as path from 'path';
import FormData from 'form-data';
import chalk from 'chalk';
// proxy sources (can be TXT lists, APIs, or raw GitHub files) // fontes de proxy (podem ser listas em txt ou APIs, ou em arquivos
export const PROXY_SOURCES = [
"example.com/proxies.txt",
"example.com/proxies.txt",
"example.com/proxies.txt",
"example.com/proxies.txt",
];
export const PROXY_FILES_FOLDER = 'proxy-lists';
// backup sources
export const BACKUP_PROXY_SOURCES = [
"https://www.proxyscan.io/download?type=http",
"https://www.proxyscan.io/download?type=https",
"https://www.proxyscan.io/download?type=socks4",
"https://www.proxyscan.io/download?type=socks5",
"https://raw.githubusercontent.com/hendrikbgr/Free-Proxy-List/master/free-proxy-list.txt",
"https://raw.githubusercontent.com/opsxcq/proxy-list/master/list.txt"
];
export class ProxyValidator {
checkUrls = [
'http://httpbin.org/ip',
'https://api.ipify.org?format=json',
'http://ip-api.com/json/',
];
allProxies = new Set();
validProxies = new Set();
axiosInstance;
discordWebhook;
constructor(discordWebhook) {
this.discordWebhook = discordWebhook;
this.axiosInstance = axios.create({
timeout: 10000,
headers: {
'User-Agent': 'ProxyValidator/1.0'
}
});
}
_log(message, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
const colorMap = {
'success': chalk.green,
'error': chalk.red,
'info': chalk.blue,
'warning': chalk.yellow
};
const colorFunc = colorMap[type];
console.log(colorFunc(`[${timestamp}] ${this._getEmoji(type)} ${message}`));
}
_getEmoji(type) {
const emojiMap = {
'success': '✅',
'error': '❌',
'info': '🔍',
'warning': '⚠️'
};
return emojiMap[type] || '';
}
async readProxiesFromFile(filePath) {
try {
const content = await fs.readFile(filePath, 'utf-8');
const proxyRegex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d+)/g;
const proxies = new Set();
let match;
const lines = content.split('\n');
for (const line of lines) {
while ((match = proxyRegex.exec(line)) !== null) {
proxies.add(`${match[1]}:${match[2]}`);
}
}
this._log(`Collected ${proxies.size} proxies from file ${filePath}`, 'success');
return proxies;
} catch (error) {
this._log(`Error reading file ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error');
return new Set();
}
}
async readAllProxyFiles() {
try {
await fs.mkdir(PROXY_FILES_FOLDER, { recursive: true });
const files = await fs.readdir(PROXY_FILES_FOLDER);
const txtFiles = files.filter(file => file.endsWith('.txt'));
for (const file of txtFiles) {
const filePath = path.join(PROXY_FILES_FOLDER, file);
const proxies = await this.readProxiesFromFile(filePath);
proxies.forEach(proxy => this.allProxies.add(proxy));
}
this._log(`Finished reading proxies from ${txtFiles.length} local files`, 'success');
} catch (error) {
this._log(`Error reading proxy files: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error');
}
}
async fetchFromSource(source) {
try {
const response = await this.axiosInstance.get(source);
const proxyRegex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d+)/g;
const proxies = new Set();
let match;
while ((match = proxyRegex.exec(response.data)) !== null) {
proxies.add(`${match[1]}:${match[2]}`);
}
this._log(`Collected ${proxies.size} proxies from ${source}`, 'success');
return proxies;
} catch (error) {
if (error instanceof Error) {
this._log(`Error collecting from ${source}: ${error.message}`, 'error');
} else {
this._log(`Error collecting from ${source}: Unknown error`, 'error');
}
return new Set();
}
}
async validateProxy(proxy) {
const checkUrl = this.checkUrls[Math.floor(Math.random() * this.checkUrls.length)];
try {
const [host, port] = proxy.split(':');
const response = await this.axiosInstance.get(checkUrl, {
proxy: {
host,
port: parseInt(port)
}
});
return response.status === 200;
} catch (error) {
return false;
}
}
async fetchAllProxies() {
this._log('Starting to collect proxies from all sources...');
await this.readAllProxyFiles();
const fetchPromises = PROXY_SOURCES.map(source => this.fetchFromSource(source));
const results = await Promise.all(fetchPromises);
results.forEach(proxySet => {
proxySet.forEach(proxy => this.allProxies.add(proxy));
});
this._log(`Total proxies collected: ${this.allProxies.size}`, 'success');
}
async validateProxies(sampleSize = 5000) {
this._log('Starting proxy validation...');
const proxiesList = Array.from(this.allProxies);
const shuffledProxies = proxiesList
.sort(() => 0.5 - Math.random())
.slice(0, sampleSize);
const validationPromises = shuffledProxies.map(async (proxy) => ({
proxy,
isValid: await this.validateProxy(proxy)
}));
const results = await Promise.all(validationPromises);
results.forEach(({ proxy, isValid }) => {
if (isValid) this.validProxies.add(proxy);
});
this._log(`Valid proxies: ${this.validProxies.size}`, 'success');
}
async saveProxies() {
try {
const timestamp = new Date().toISOString().replace(/:/g, '-');
const filename = `valid_proxies_${timestamp}.txt`;
const filepath = path.join('proxies', filename);
await fs.mkdir('proxies', { recursive: true });
await fs.writeFile(filepath, Array.from(this.validProxies).join('\n'));
this._log(`Proxies saved to ${filepath}`, 'success');
return filepath;
} catch (error) {
this._log(`Error saving proxies: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error');
return null;
}
}
async sendToDiscord(filepath) {
try {
const form = new FormData();
form.append('file', await fs.readFile(filepath), {
filename: path.basename(filepath),
contentType: 'text/plain'
});
form.append('payload_json', JSON.stringify({
content: '',
embeds: [
{
color: 0x000000,
title: "📡 **Proxy Validation Report** 📡",
description: "Here is a detailed summary of proxy collection and validation.",
fields: [
{
name: "🌍 **Total Proxies Collected**",
value: `\`\`\`${this.allProxies.size}\`\`\``,
inline: true
},
{
name: "✅ **Valid Proxies**",
value: `\`\`\`${this.validProxies.size}\`\`\``,
inline: true
},
{
name: "📅 **Validation Date**",
value: `\`\`\`${new Date().toLocaleString()}\`\`\``,
inline: false
},
{
name: "🔍 **Validation Details**",
value: `- Collected from various trusted sources.\n` +
`- Validation was performed on a large number of proxies ensuring accuracy and quality.\n` +
`- Sources include public lists, APIs, and international proxies.\n`,
inline: false
},
{
name: "📂 **Proxy File**",
value: "The file with the list of valid proxies has been generated and is attached.",
inline: false
}
],
image: {
url: "https://i.pinimg.com/736x/3b/d9/dc/3bd9dc9c89ad67c4b0992680bb248cb8.jpg"
},
footer: {
text: 'Proxy Validator - 2025',
icon_url: 'https://avatars.githubusercontent.com/u/154631371?v=4&size=64'
},
timestamp: new Date()
}
]
}));
await this.axiosInstance.post(this.discordWebhook, form, {
headers: form.getHeaders()
});
this._log('Report successfully sent to Discord!', 'success');
} catch (error) {
this._log(`Error sending to Discord: ${error instanceof Error ? error.message : 'Unknown error'}`, 'error');
}
}
}
(async () => {
const discordWebhook = process.env.DISCORD_WEBHOOK || 'YOUR_WEBHOOK_HERE';
const validator = new ProxyValidator(discordWebhook);
await validator.fetchAllProxies();
await validator.validateProxies();
const filepath = await validator.saveProxies();
if (filepath) {
await validator.sendToDiscord(filepath);
}
})();