TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
917 stars 238 forks source link

SocksClientError: connect ETIMEDOUT xxx.xxx.xxx.xxx:xxxx #318

Closed TutorialMan7727 closed 3 months ago

TutorialMan7727 commented 3 months ago

When writing some code generate a random proxy from an online list I get the following error

SocksClientError: connect ETIMEDOUT 103.104.214.239:1080
    at SocksClient.closeSocket (x\node_modules\socks\build\client\socksclient.js:390:32)
    at SocksClient.onErrorHandler (x\node_modules\socks\build\client\socksclient.js:363:14)
    at Socket.onError (xx\node_modules\socks\build\client\socksclient.js:225:38)
    at Object.onceWrapper (node:events:634:26)
    at Socket.emit (node:events:519:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ClientRequest instance at:
    at _destroy (node:_http_client:880:13)
    at onSocketNT (node:_http_client:900:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  options: {
    proxy: { host: 'xxx.xxx.xxx.xxx', port: xxxx, type: 4 },
    destination: { host: '34.117.186.192', port: 443 },
    command: 'connect',
    timeout: undefined,
    socket_options: undefined
  }
}

This is my code:

const https = require("https");
const { SocksProxyAgent } = require("socks-proxy-agent");
import { faker } from "@faker-js/faker";

const GenProxy = (proxys: string[]): string => {
  const currentProxy: string = proxys[faker.number.int(proxys.length)];
  const proxy = `socks4://${currentProxy}`;
  console.log(`[Proxy] ${proxy}`);

  return proxy;
};

(async () => {
  const proxys: string[] = (
    await (
      await fetch(
        "https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/socks4.txt"
      )
    ).text()
  ).split("\n");

  const agent = new SocksProxyAgent(GenProxy(proxys), {
    rejectUnauthorized: false,
  });

  https.get("https://ipinfo.io", { agent }, (res: any) => {
    console.log(res.headers);
    res.pipe(process.stdout);
  });
})();

I belive this is an issue with the package and not my code

TutorialMan7727 commented 3 months ago

Duplicte of #319