Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const checkProxy = require('check-proxy').check;
- var fs = require('fs');
- //process.setMaxListeners(0);
- /*process.on('unhandledRejection', (reason, p) => {
- console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
- // application specific logging, throwing an error, or other logic here
- });*/
- function timeout(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- var threadLimit = async function(arrfunc) {
- var l = arrfunc.length;
- var i = 0;
- var tm = 10;
- var tn = 0;
- var r = [];
- var donecount = 0;
- async function s() {
- for (; tn < tm; tn++) {
- if (i < l) {
- r[i] = arrfunc[i]();
- (function(b) {
- r[i].then((proxyrespone) => {
- donecount++;
- tn--;
- r[b] = proxyrespone;
- s();
- //console.log(donecount + "/" + l);
- });
- })(i);
- i++;
- }
- await timeout(1000);
- }
- //return await Promise.all(r);
- }
- await s();
- var bag = 0;
- while ((await Promise.all(r)).length < l) {
- await Promise.all(r);
- bag++;
- //console.dir("этапов " + bag);
- //console.dir(r);
- }
- return await Promise.all(r);
- };
- (async () => {
- broTestProxy = (proxyip, proxyport) => {
- return () => {
- return (async () => {
- var rez = false;
- try {
- rez = await checkProxy({
- testHost: 'nodetest.bro-dev.tk', // put your ping server url here
- proxyIP: proxyip, // proxy ip to test
- proxyPort: proxyport, // proxy port to test
- localIP: "188.134.2.171", // local machine IP address to test
- connectTimeout: 60, // curl connect timeout, sec
- timeout: 60, // curl timeout, sec
- websites: [{
- name: 'example',
- url: 'http://www.example.com/',
- regex: /example/gim, // expected result - regex
- }, {
- name: 'yandex',
- url: 'http://www.yandex.ru/',
- regex: /yandex/gim, // expected result - regex
- }, {
- name: 'google',
- url: 'http://www.google.com/',
- regex: function(html) { // expected result - custom function
- return html && html.indexOf('google') != -1;
- },
- }, {
- name: 'amazon',
- url: 'http://www.amazon.com/',
- regex: 'Amazon', // expected result - look for this string in the output
- }, ]
- });
- console.log(rez);
- await fs.appendFileSync('good.txt', proxyip+':'+proxyport+"rn");
- return rez;
- } catch (er) {
- console.log(er);
- rez = {
- ip: proxyip,
- port: proxyport,
- 'get': false,
- };
- await fs.appendFileSync('bad.txt', proxyip+':'+proxyport+"rn");
- console.log(rez);
- return rez;
- }
- })();
- }
- }
- var time = process.hrtime();
- regprox = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}/g;
- proxylist = fs.readFileSync('proxylist.txt', 'utf8').match(regprox);
- var proxyarray = [];
- var tt = [];
- for (var ipport of proxylist) {
- ipport = ipport.split(":");
- var proxyip = ipport[0];
- var proxyport = ipport[1];
- proxyarray.push(broTestProxy(proxyip, proxyport));
- tt.push([proxyip, proxyport]);
- }
- var result = await threadLimit(proxyarray);
- console.dir(result.filter((el) => {
- return Array.isArray(el);
- }).length);
- console.dir(proxyarray.length);
- time = process.hrtime(time);
- console.dir(time);
- })();
Add Comment
Please, Sign In to add comment