|
| 1 | +const WebSocket = require('ws'); |
| 2 | +const fs = require('fs'); |
| 3 | +const crypto = require('crypto'); |
| 4 | +const { SocksProxyAgent } = require('socks-proxy-agent'); |
| 5 | +const { v4: uuidv4, v3: uuidv3 } = require('uuid'); |
| 6 | +const pino = require('pino'); |
| 7 | +const logger = pino({ level: 'info', transport: { target: 'pino-pretty' } }); |
| 8 | +const config = require('./configuration'); |
| 9 | + |
| 10 | +let CoderMarkPrinted = false; |
| 11 | + |
| 12 | +const cl = { |
| 13 | + gr: '\x1b[32m', |
| 14 | + br: '\x1b[34m', |
| 15 | + red: '\x1b[31m', |
| 16 | + yl: '\x1b[33m', |
| 17 | + gb: '\x1b[4m', |
| 18 | + rt: '\x1b[0m' |
| 19 | +}; |
| 20 | + |
| 21 | +function CoderMark() { |
| 22 | + if (!CoderMarkPrinted) { |
| 23 | + console.log(` |
| 24 | +╭━━━╮╱╱╱╱╱╱╱╱╱╱╱╱╱╭━━━┳╮ |
| 25 | +┃╭━━╯╱╱╱╱╱╱╱╱╱╱╱╱╱┃╭━━┫┃${cl.gr} |
| 26 | +┃╰━━┳╮╭┳━┳━━┳━━┳━╮┃╰━━┫┃╭╮╱╭┳━╮╭━╮ |
| 27 | +┃╭━━┫┃┃┃╭┫╭╮┃╭╮┃╭╮┫╭━━┫┃┃┃╱┃┃╭╮┫╭╮╮${cl.br} |
| 28 | +┃┃╱╱┃╰╯┃┃┃╰╯┃╰╯┃┃┃┃┃╱╱┃╰┫╰━╯┃┃┃┃┃┃┃ |
| 29 | +╰╯╱╱╰━━┻╯╰━╮┣━━┻╯╰┻╯╱╱╰━┻━╮╭┻╯╰┻╯╰╯${cl.rt} |
| 30 | +╱╱╱╱╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱╱╱╱╭━╯┃ |
| 31 | +╱╱╱╱╱╱╱╱╱╱╱╰╯╱╱╱╱╱╱╱╱╱╱╱╰━━╯ |
| 32 | +\n${cl.gb}${cl.yl}getGrass Minner Bot ${cl.rt}${cl.gb}v0.2${cl.rt} |
| 33 | + `); |
| 34 | + CoderMarkPrinted = true; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +async function connectToWss(socks5Proxy, userId) { |
| 39 | + const deviceId = uuidv3(socks5Proxy, uuidv3.DNS); |
| 40 | + logger.info(deviceId); |
| 41 | + while (true) { |
| 42 | + try { |
| 43 | + await new Promise(resolve => setTimeout(resolve, Math.random() * 900 + 100)); |
| 44 | + const customHeaders = { "User-Agent": config.UserAgent }; |
| 45 | + const uriList = ["wss://proxy2.wynd.network:4444/", "wss://proxy2.wynd.network:4650/"]; |
| 46 | + const uri = uriList[Math.floor(Math.random() * uriList.length)]; |
| 47 | + const agent = new SocksProxyAgent(socks5Proxy); |
| 48 | + const ws = new WebSocket(uri, { |
| 49 | + agent: agent, |
| 50 | + headers: { |
| 51 | + "Origin": config["Origin"], |
| 52 | + "User-Agent": customHeaders["User-Agent"] |
| 53 | + }, |
| 54 | + rejectUnauthorized: false |
| 55 | + }); |
| 56 | + ws.on('open', () => { |
| 57 | + const sendPing = () => { |
| 58 | + const sendMessage = JSON.stringify({ id: uuidv4(), version: "1.0.0", action: "PING", data: {} }); |
| 59 | + logger.debug(sendMessage); |
| 60 | + ws.send(sendMessage); |
| 61 | + setTimeout(sendPing, 110000); |
| 62 | + }; |
| 63 | + sendPing(); |
| 64 | + }); |
| 65 | + |
| 66 | + ws.on('message', (data) => { |
| 67 | + const message = JSON.parse(data); |
| 68 | + logger.info(message); |
| 69 | + if (message.action === "AUTH") { |
| 70 | + const authResponse = { |
| 71 | + id: message.id, |
| 72 | + origin_action: "AUTH", |
| 73 | + result: { |
| 74 | + browser_id: deviceId, |
| 75 | + user_id: userId, |
| 76 | + user_agent: customHeaders['User-Agent'], |
| 77 | + timestamp: Math.floor(Date.now() / 1000), |
| 78 | + device_type: "extension", |
| 79 | + version: "4.26.2", |
| 80 | + extension_id: config.extension_id |
| 81 | + } |
| 82 | + }; |
| 83 | + logger.debug(authResponse); |
| 84 | + ws.send(JSON.stringify(authResponse)); |
| 85 | + } else if (message.action === "PONG") { |
| 86 | + const pongResponse = { id: message.id, origin_action: "PONG" }; |
| 87 | + logger.debug(pongResponse); |
| 88 | + ws.send(JSON.stringify(pongResponse)); |
| 89 | + } |
| 90 | + }); |
| 91 | + |
| 92 | + await new Promise((resolve, reject) => { |
| 93 | + ws.on('close', () => reject(new Error('WebSocket closed'))); |
| 94 | + ws.on('error', (error) => reject(error)); |
| 95 | + }); |
| 96 | + } catch (e) { |
| 97 | + logger.error(`Error with proxy ${socks5Proxy}: ${e.message}`); |
| 98 | + if (["Host unreachable", "[SSL: WRONG_VERSION_NUMBER]", "invalid length of packed IP address string", "Empty connect reply", "Device creation limit exceeded", "sent 1011 (internal error) keepalive ping timeout; no close frame received"].some(msg => e.message.includes(msg))) { |
| 99 | + logger.info(`Removing error proxy from the list: ${socks5Proxy}`); |
| 100 | + removeProxyFromList(socks5Proxy); |
| 101 | + return null; |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +async function main() { |
| 108 | + const proxyFile = config.proxyFile; |
| 109 | + const userId = config.userId; |
| 110 | + const allProxies = fs.readFileSync(proxyFile, 'utf-8').split('\n').filter(Boolean); |
| 111 | + let activeProxies = allProxies.sort(() => 0.5 - Math.random()).slice(0, 100); |
| 112 | + let tasks = new Map(activeProxies.map(proxy => [connectToWss(proxy, userId), proxy])); |
| 113 | + |
| 114 | + while (true) { |
| 115 | + const [done] = await Promise.race([...tasks.keys()].map(p => p.then(() => [p]))); |
| 116 | + const failedProxy = tasks.get(done); |
| 117 | + tasks.delete(done); |
| 118 | + |
| 119 | + if (await done === null) { |
| 120 | + logger.info(`Removing and replacing failed proxy: ${failedProxy}`); |
| 121 | + activeProxies = activeProxies.filter(p => p !== failedProxy); |
| 122 | + const newProxy = allProxies[Math.floor(Math.random() * allProxies.length)]; |
| 123 | + activeProxies.push(newProxy); |
| 124 | + tasks.set(connectToWss(newProxy, userId), newProxy); |
| 125 | + } |
| 126 | + |
| 127 | + for (const proxy of activeProxies) { |
| 128 | + if (![...tasks.values()].includes(proxy)) { |
| 129 | + tasks.set(connectToWss(proxy, userId), proxy); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +function removeProxyFromList(proxy) { |
| 136 | + const proxyFile = config.proxyFile; |
| 137 | + const proxyList = fs.readFileSync(proxyFile, "utf-8").split('\n'); |
| 138 | + const updatedList = proxyList.filter(line => line.trim() !== proxy); |
| 139 | + fs.writeFileSync(proxyFile, updatedList.join('\n')); |
| 140 | +} |
| 141 | +CoderMark(); |
| 142 | +main().catch(console.error); |
0 commit comments