When I attempt to run the following code I get an connect ETIMEDOUT error
import type { Proxy, ProxyList } from "./proxyTypes";
import axios from "axios";
import { SocksProxyAgent } from "socks-proxy-agent";
const getProxys = async (): Promise<ProxyList> => {
const proxyUrl: string =
"https://proxylist.geonode.com/api/proxy-list?limit=500&page=1&sort_by=lastChecked&sort_type=desc";
return (await axios.get(proxyUrl)).data;
};
const getRandomProxy = (proxys: ProxyList): Proxy => {
return proxys.data[Math.floor(Math.random() * proxys.data.length)];
};
const proxyToUri = (proxy: Proxy): string => {
return `${proxy.protocols[0]}://${proxy.ip}:${proxy.port}`;
};
(async () => {
const proxys = await getProxys();
const proxy = getRandomProxy(proxys);
const uri = proxyToUri(proxy);
console.log(uri + " - " + proxy.responseTime + "ms");
const httpsAgent = new SocksProxyAgent(uri);
const client = axios.create({ httpsAgent });
client
.get("https://icanhazip.com/")
.then((res) => {
console.log(res.data);
})
.catch((e) => {
console.log(e.message);
});
})();
I tried using a vpn and running on cloud services. It should return the proxys ip to the console. An exapmle output of the current code lookes like
socks4://212.3.105.11:4145 – 3308ms
connect ECONNREFUSED 212.3.105.11:4145
but should look like
socks4://185.161.186.92:54321 – 993ms
185.161.186.92