const axios = require("axios"); const fs = require("fs"); const csv = require("csv-writer").createObjectCsvWriter; class Modca { constructor(testUrl = "https://example.com", source = 1) { this.testUrl = testUrl; this.source = source; this.proxies = []; } async fetchFromWebsite() { const url = "https://free-proxy-list.net/"; try { const response = await axios.get(url); const proxyRegex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<\/td>(\d+?)<\/td>/g; let match; while ((match = proxyRegex.exec(response.data)) !== null) { this.proxies.push(`${match[1]}:${match[2]}`); } } catch (error) { console.error(`⚠️ Failed to fetch proxies from website: ${error.message}`); } } fetchFromFile() { const filename = "proxies.txt"; if (!fs.existsSync(filename)) { console.error(`⚠️ The file ${filename} does not exist! Please create it and add proxies.`); return; } const data = fs.readFileSync(filename, "utf8"); this.proxies = data.split("\n").filter(line => line.trim()); } async checkProxy(proxy) { try { console.log(`🔍 Checking proxy: ${proxy}...`); const startTime = Date.now(); const response = await axios.get(this.testUrl, { proxy: { host: proxy.split(":")[0], port: parseInt(proxy.split(":")[1]), }, timeout: 5000, }); const endTime = Date.now(); const responseTime = endTime - startTime; if (response.status === 200) { const score = this.calculateIpScore(responseTime); console.log(`✅ Proxy ${proxy} is working! Quality Score: ${score}/100`); return { proxy, score }; } } catch (error) { console.error(`❌ Proxy ${proxy} failed: ${error.message}`); } return null; } calculateIpScore(responseTime) { const maxTime = 5000; // 5 seconds if (responseTime < 100) return 100; if (responseTime > maxTime) return 0; return Math.round((1 - responseTime / maxTime) * 100); } async checkProxies(maxChecks) { const workingProxies = []; const proxyChecks = this.proxies.slice(0, maxChecks).map(proxy => this.checkProxy(proxy)); const results = await Promise.all(proxyChecks); results.forEach(result => { if (result) workingProxies.push(result); }); return workingProxies; } saveToCsv(workingProxies) { const filename = "working_proxies.csv"; const csvWriter = csv({ path: filename, header: [ { id: "proxy", title: "IP:Port" }, { id: "score", title: "Quality Score" }, ], }); csvWriter.writeRecords(workingProxies) .then(() => console.log(`💾 Working proxies have been saved to ${filename}`)) .catch(err => console.error(`⚠️ Failed to save CSV: ${err.message}`)); } async run() { if (this.source === 1) { await this.fetchFromWebsite(); } else if (this.source === 2) { this.fetchFromFile(); } if (this.proxies.length === 0) { console.error("❌ No proxies found, please check the source."); return; } const tanyaTotal = parseInt(prompt("Enter the number of proxies to check -> ") || "1"); console.log("⏳ Checking proxies, please wait..."); const workingProxies = await this.checkProxies(tanyaTotal); if (workingProxies.length === 0) { console.error("❌ No working proxies found."); return; } this.saveToCsv(workingProxies); workingProxies.forEach(({ proxy, score }, index) => { console.log(`✅ Proxy ${index + 1} -> ${proxy} (Quality Score: ${score}/100)`); }); const ask = prompt("🔁 Do you want to check more proxies? (Y/n) "); if (ask.toLowerCase() === "y") { this.run(); } else { console.log("👋 Goodbye!"); } } } // Example usage const testUrl = prompt("🌍 Enter the website URL to test proxies (default: https://example.com): ") || "https://example.com"; const source = parseInt(prompt("1️⃣ Fetch proxies from website\n2️⃣ Use a text file (proxies.txt)\n🔢 Choose proxy source (1 or 2): ")); const modca = new Modca(testUrl, source); modca.run();
Commentaires



Font Size
+
16
-
lines height
+
2
-