I am trying to automate opening web page and run it through a local proxy
I have used this docker image
docker pull zeta0/alpine-tor:latest
and run it with this command:
docker run -d -p 5566:5566 -p 2090:2090 -e tors=25 zeta0/alpine-tor
I can see that the local proxy is working because I tested it with curl with this command:
curl --socks5 localhost:5566 http://httpbin.org/ip I get a response with a random IP address, different from my IP address.
I am using NightmareJS to open a browser window. I initialize the nightmare object as follows:
const proxyNightmare = nightmare({
executionTimeout: 1000000, // in ms
waitTimeout: 1000000, // in ms
switches: {
'proxy-server': proxy, // set the proxy server here ...
'ignore-certificate-errors': true
},
width: randomScreenElement[0],
height: randomScreenElement[1],
show: true
});
and after that i open a new browser window with the following code:
const minimist = require('./node_modules/minimist');
const platform = require('./node_modules/platform');
const nightmare = require('./node_modules/nightmare');
let args = minimist(process.argv.slice(2), {
alias: {
ur: 'url',
px: 'proxy',
pt: 'port',
us: 'user',
ps: 'pass',
ws: 'windows',
te: 'time',
re: 'referrals'
},
default: {
url: 'https://testsite.com', // Url to navigate
proxy: 'http://localhost', // Proxy address 1.127.0.1, localhost or example.com
port: '5566', // Proxy port
user: '', // Proxy username
pass: '', // Proxy pass
windows: '1', // Total of windows to be opened
time: '3', // Total time of the section in minutes
referrals: 'no'
}
});
// console.log('args:', args);
const openWebsite = async id => {
'use strict';
let url = args.url, screenArray;
let proxy = args.proxy ? args.proxy + ':' + args.port : '';
let user = args.user;
let pass = args.pass;
let miliseconds = (args.time == 'random') ? randomTimeFromInterval(60, 300) : (args.time * 6000) / 6;
let userAgentObj = require("./useragent/most-common.json");
let obj = JSON.parse(JSON.stringify(userAgentObj));
let ua = obj.randomElement().ua;
let info = platform.parse(ua); // Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.2; en; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 11.52
let osFamily = info.os.family; // Android, IOS, Linux, etc..
let blacklist = [
'https://www.facebook.com/ppplayermusic',
'https://instagram.com/ppplayermusic',
'https://ppplayer.com/public/search',
'https://ppplayer.com/search',
'https://ppplayer.com/login',
'https://ppplayer.com/register'
];
let randomScreenElement = screenArray.randomElement();
const proxyNightmare = nightmare({
executionTimeout: 1000000, // in ms
waitTimeout: 1000000, // in ms
switches: {
'proxy-server': proxy, // set the proxy server here ...
'ignore-certificate-errors': true
},
width: randomScreenElement[0],
height: randomScreenElement[1],
show: true
});
let gotourl, addtourl;
let utm_source = ['Google', 'facebook', 'twitter', 'instagram', 'Bing', 'Yahoo', 'DuckDuckGo', 'LinkedIn', 'Reddit', 'DuckDuckGo', 'Quora']
let utm_medium = ['cpc', 'Organic'];
let utm_campaign = ['', ''];
let utm_term = ['ppplayer', 'ppplayer+music', 'music', 'online', 'listen+online+music', 'ppplayer+online', 'play+music', 'digital', 'ppplayer+playlist', 'artist', 'playlist', 'ppplayer+web'];
url = (addtourl != '' && args.referrals == 'yes') ? url + addtourl : url;
// GO
try {
await proxyNightmare
.authentication(user, pass)
.useragent(ua)
.goto(url)
.wait(miliseconds)
.evaluate((miliseconds, blacklist) => {
}, miliseconds, blacklist)
.wait(miliseconds)
.wait(miliseconds)
.end()
.then(function (result) {
console.log("result=>: " + result);
})
.catch(function (error) {
console.error('Error->:', error);
});
} catch (e) {
console.error("Error+>: ", e);
}
}
for (var i = 0; i < args.windows; i++) {
openWebsite(i)
.then(a => console.dir(a))
.catch(e => console.error(e));
}
When I run the openWebsite function, I get the error code -111 ERR_TUNNEL_CONNECTION_FAILED
Any ideas?