/** * Config target host * * */ var targetVersion = '4.9', countries = null, //['bg'], wanCheckUrl = 'https://api.ipify.org?format=json', requestTimeout = 8000, maxRequests = 50000; //0 = Unlimited let randUserAgent; /** * Set max IO operations, so we do not see warning during execution * */ process.setMaxListeners(maxRequests); require('events').EventEmitter.defaultMaxListeners = maxRequests; const axios = require('axios'); const SocksProxyAgent = require('socks-proxy-agent').SocksProxyAgent; var proxyList = []; var wanIp = //Will be determined automaticaly or assign it manualy gettingProxies = null, // `gettingProxies` is an event emitter object. currentRequestCount = currentWebsiteIndex = 0 async function getWAN() { randUserAgent = (await import('rand-user-agent')).default; axios({ method: 'get', 'url': wanCheckUrl, timeout: requestTimeout, responseType: 'json' }).then((result) => { wanIp = result.data.ip; if (!gettingProxies) { initProxyListener(); //Init processor processor(); } }, (err) => { console.error('Unable to get public WAN', err.message); process.exit(1); }) } // TODO: //destroy the old gettingProxies function initProxyListener() { if (gettingProxies) { gettingProxies = null; } gettingProxies = require('proxy-lists').getProxies({ countries: countries, protocols: ['socks4', 'socks5']//['http', 'https'] }); gettingProxies.on('data', function (proxies) { for (var a in proxies) { processRawProxy(proxies[a]) } }); gettingProxies.on('error', function (error) { // console.error(error); }); gettingProxies.once('end', function () { writeOnSingleLine('Stopped listening for proxies. Currently there are ' + proxyList.length + ' proxies in memory') }); } function processRawProxy(proxy) { const proxyOptions = `${proxy.protocols[proxy.protocols.length - 1]}://${proxy.ipAddress}:${proxy.port}`; // your sock5 host and port; const httpsAgent = new SocksProxyAgent(proxyOptions); var req = axios({ httpsAgent, 'url': wanCheckUrl, // responseType: 'text', timeout: requestTimeout }).then(function (result) { if (result.data.ip && result.data.ip.indexOf(wanIp) <= -1 && result.data.ip !== 'Unauthorized') proxyList.push(proxy) }, (err) => { removeProxy(proxy); // writeOnSingleLine(err) }) //Do not remove this handler, as ECONNRESET is killing the process req.on("error", function (err) { }); } function callWithProxy(proxy) { const proxyOptions = `${proxy.protocols[proxy.protocols.length - 1]}://${proxy.ipAddress}:${proxy.port}`; // your sock5 host and port; const httpsAgent = new SocksProxyAgent(proxyOptions); currentRequestCount++; var options = { method: 'post', url: 'https://www.vesti.bg/polls/showResults/427/1/1', timeout: requestTimeout, httpsAgent, responseType: 'text', headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-GB,en;q=0.8', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin', 'Sec-GPC': '1', 'User-Agent': randUserAgent("desktop"), 'Origin': 'https://www.vesti.bg', 'Cookie': 'PHPSESSID=5543824c9ec079f5a4f16f409b4bcf9f; articleReferrer=a%3A1%3A%7Bs%3A10%3A%22article_id%22%3Bs%3A7%3A%226171891%22%3B%7D', 'Referer': 'https://www.vesti.bg/bulgaria/vypros-na-denia-podkrepiate-li-predostavianeto-na-voenna-pomosht-na-ukrajna-6171891', 'Connection': 'keep-alive', 'X-Requested-With': 'XMLHttpRequest' } } var req = axios(options).then(function (result) { currentRequestCount-- writeOnSingleLine(result.data.match(new RegExp('