Repository navigation
Expand file tree
/
Copy pathtest-proxy.js
More file actions
113 lines (94 loc) · 4.39 KB
/
Copy pathtest-proxy.js
File metadata and controls
113 lines (94 loc) · 4.39 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
require('dotenv').config();
const puppeteer = require('puppeteer');
const config = require('./config');
async function testProxy() {
console.log('🧪 Proxy Connection Tester\n');
if (!config.USE_PROXY) {
console.log('❌ Proxy is disabled in .env file');
console.log('💡 Set USE_PROXY=true to test proxy connection');
return;
}
if (!config.PROXY_HOST || !config.PROXY_PORT) {
console.log('❌ Missing proxy configuration');
console.log('💡 Check PROXY_HOST and PROXY_PORT in .env file');
return;
}
console.log(`🔒 Testing ${config.PROXY_TYPE.toUpperCase()} proxy: ${config.PROXY_HOST}:${config.PROXY_PORT}`);
console.log(`⏱️ Timeout: ${config.PROXY_TIMEOUT}ms, Retries: ${config.PROXY_RETRY_ATTEMPTS}\n`);
const launchOptions = {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
};
// Add proxy configuration
const proxyUrl = `${config.PROXY_TYPE}://${config.PROXY_HOST}:${config.PROXY_PORT}`;
launchOptions.args.push(`--proxy-server=${proxyUrl}`);
launchOptions.args.push('--ignore-certificate-errors');
launchOptions.args.push('--ignore-ssl-errors');
let browser;
try {
browser = await puppeteer.launch(launchOptions);
const page = await browser.newPage();
// Set authentication if provided
if (config.PROXY_USERNAME && config.PROXY_PASSWORD) {
console.log('🔐 Setting proxy authentication...');
await page.authenticate({
username: config.PROXY_USERNAME,
password: config.PROXY_PASSWORD
});
}
// Test connection
for (let attempt = 1; attempt <= config.PROXY_RETRY_ATTEMPTS; attempt++) {
try {
console.log(`📡 Attempt ${attempt}/${config.PROXY_RETRY_ATTEMPTS}: Testing connection...`);
const startTime = Date.now();
await page.goto('https://httpbin.org/ip', {
waitUntil: 'domcontentloaded',
timeout: config.PROXY_TIMEOUT
});
const responseTime = Date.now() - startTime;
const ipInfo = await page.evaluate(() => {
try {
return JSON.parse(document.body.innerText);
} catch {
return { origin: document.body.innerText.trim() };
}
});
console.log(`✅ SUCCESS! Proxy is working`);
console.log(`📍 Your IP: ${ipInfo.origin}`);
console.log(`⚡ Response time: ${responseTime}ms`);
// Test Discord accessibility
console.log('\n🎮 Testing Discord accessibility...');
const discordStart = Date.now();
await page.goto('https://discord.com', {
waitUntil: 'domcontentloaded',
timeout: config.PROXY_TIMEOUT
});
const discordTime = Date.now() - discordStart;
console.log(`✅ Discord accessible through proxy`);
console.log(`⚡ Discord response time: ${discordTime}ms`);
console.log('\n🎉 Proxy configuration is working perfectly!');
return;
} catch (error) {
console.log(`❌ Attempt ${attempt} failed: ${error.message}`);
if (attempt < config.PROXY_RETRY_ATTEMPTS) {
console.log('⏳ Waiting 5 seconds before retry...\n');
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
}
console.log('\n💥 All attempts failed!');
console.log('🔧 Troubleshooting tips:');
console.log(' 1. Check proxy credentials in .env file');
console.log(' 2. Verify proxy server is online');
console.log(' 3. Try different PROXY_TYPE (http/socks5)');
console.log(' 4. Check firewall/network restrictions');
} catch (error) {
console.log('❌ Browser launch failed:', error.message);
} finally {
if (browser) {
await browser.close();
}
}
}
// Run the test
testProxy().catch(console.error);