0
var fs = require('fs');
var socks = require('socks');
var proxies = fs.readFileSync('proxies.txt').replace(/\r/g, '').split('\n');

function createAgent() {
         var proxy = proxies[Math.floor(Math.random() * proxies.length)];
         return new socks.Agent({
                ipaddress: proxy[0],
                port: proxy[1],
                type: 5
         });
}

Socks module has changed the libraries and this script wont work anymore. Can anybody help me and explain this ?

xmile90
  • 3
  • 6
  • This doesn't look like it should ever have worked. `proxies` is an array of strings, `proxy` is a string chosen at random from the array, and the IP address and port number are set to the first two characters of that string. I think it's missing a step where it parses the line of the file. For example, if the lines look like `192.168.62.214 8080`, then you could write `var proxy = proxies[Math.floor(Math.random() * proxies.length)].split(/\s+/);`. – David Knipe Dec 30 '17 at 18:03
  • Still it will not work because it's not there the problem. Socks updated their libraries and i am not sure how to do it now. Have a look at socks modules: https://www.npmjs.com/package/socks and if i do it like you said it will be an array of strings but we actually want a parameter "url" which should be a string not an array! – xmile90 Jan 07 '18 at 08:52
  • I meant that `url` should be `proxy[0]` or whatever it is. Although actually I don't see `url` mentioned on that page. Nor do I see a constructor named `Agent`. But I don't know what format your config file so I can't be sure. But basically you want to create an `options` object as in Quick Start Example, but replace `ipaddress`, `port` and other parameters with sensible values from the config file or wherever. Then do `return socks.SocksClient.createConnection(options);`. – David Knipe Jan 07 '18 at 18:14
  • I actually do not understand but i will keep trying. It actually works with old libraries of socks but with the new ones nope. – xmile90 Jan 07 '18 at 21:56

1 Answers1

0

I didn't expect to see you here, I was having the same problem but then I read your question and you stated

Socks module has changed the libraries

That gave me the idea to install an older version of socks.

npm install socks@1

And that worked. It worked for me, it should work for you.

Sh0T
  • 72
  • 1
  • 6