Guest User

Untitled

a guest
Nov 19th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. const checkProxy = require('check-proxy').check;
  2. var fs = require('fs');
  3. //process.setMaxListeners(0);
  4. /*process.on('unhandledRejection', (reason, p) => {
  5. console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
  6. // application specific logging, throwing an error, or other logic here
  7. });*/
  8. function timeout(ms) {
  9. return new Promise(resolve => setTimeout(resolve, ms));
  10. }
  11. var threadLimit = async function(arrfunc) {
  12. var l = arrfunc.length;
  13. var i = 0;
  14. var tm = 10;
  15. var tn = 0;
  16. var r = [];
  17. var donecount = 0;
  18. async function s() {
  19. for (; tn < tm; tn++) {
  20. if (i < l) {
  21. r[i] = arrfunc[i]();
  22. (function(b) {
  23. r[i].then((proxyrespone) => {
  24. donecount++;
  25. tn--;
  26. r[b] = proxyrespone;
  27. s();
  28. //console.log(donecount + "/" + l);
  29. });
  30. })(i);
  31. i++;
  32. }
  33. await timeout(1000);
  34. }
  35. //return await Promise.all(r);
  36. }
  37. await s();
  38. var bag = 0;
  39. while ((await Promise.all(r)).length < l) {
  40. await Promise.all(r);
  41. bag++;
  42. //console.dir("этапов " + bag);
  43. //console.dir(r);
  44. }
  45. return await Promise.all(r);
  46. };
  47. (async () => {
  48. broTestProxy = (proxyip, proxyport) => {
  49. return () => {
  50. return (async () => {
  51. var rez = false;
  52. try {
  53. rez = await checkProxy({
  54. testHost: 'nodetest.bro-dev.tk', // put your ping server url here
  55. proxyIP: proxyip, // proxy ip to test
  56. proxyPort: proxyport, // proxy port to test
  57. localIP: "188.134.2.171", // local machine IP address to test
  58. connectTimeout: 60, // curl connect timeout, sec
  59. timeout: 60, // curl timeout, sec
  60. websites: [{
  61. name: 'example',
  62. url: 'http://www.example.com/',
  63. regex: /example/gim, // expected result - regex
  64. }, {
  65. name: 'yandex',
  66. url: 'http://www.yandex.ru/',
  67. regex: /yandex/gim, // expected result - regex
  68. }, {
  69. name: 'google',
  70. url: 'http://www.google.com/',
  71. regex: function(html) { // expected result - custom function
  72. return html && html.indexOf('google') != -1;
  73. },
  74. }, {
  75. name: 'amazon',
  76. url: 'http://www.amazon.com/',
  77. regex: 'Amazon', // expected result - look for this string in the output
  78. }, ]
  79. });
  80. console.log(rez);
  81. await fs.appendFileSync('good.txt', proxyip+':'+proxyport+"rn");
  82. return rez;
  83. } catch (er) {
  84. console.log(er);
  85. rez = {
  86. ip: proxyip,
  87. port: proxyport,
  88. 'get': false,
  89. };
  90. await fs.appendFileSync('bad.txt', proxyip+':'+proxyport+"rn");
  91. console.log(rez);
  92. return rez;
  93. }
  94. })();
  95. }
  96. }
  97. var time = process.hrtime();
  98. regprox = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}/g;
  99. proxylist = fs.readFileSync('proxylist.txt', 'utf8').match(regprox);
  100. var proxyarray = [];
  101. var tt = [];
  102. for (var ipport of proxylist) {
  103. ipport = ipport.split(":");
  104. var proxyip = ipport[0];
  105. var proxyport = ipport[1];
  106. proxyarray.push(broTestProxy(proxyip, proxyport));
  107. tt.push([proxyip, proxyport]);
  108. }
  109. var result = await threadLimit(proxyarray);
  110. console.dir(result.filter((el) => {
  111. return Array.isArray(el);
  112. }).length);
  113. console.dir(proxyarray.length);
  114. time = process.hrtime(time);
  115. console.dir(time);
  116. })();
Add Comment
Please, Sign In to add comment