proxy-chain icon indicating copy to clipboard operation
proxy-chain copied to clipboard

allow to use proxying without authorization

Open anton-lsports opened this issue 3 years ago • 12 comments

Hi,

First thank you for the package is very nice and useful!

for my use scenario I need to use some free proxies that doesn't require authentication (username, & password).

possible solutions I found for this is:

  1. here https://github.com/apify/proxy-chain/blob/e4367ce73f16fd0d76cf617e80dd7bf541305fe5/src/anonymize_proxy.ts#L47 to remove this condition.
  2. add property for in options that let me use the proxy without username and password.

thanks a lot!

anton-lsports avatar Aug 24 '22 09:08 anton-lsports

So you'd like the anonymizeProxy function to return a URL like http://localhost:8453 instead of the password-less http://myproxy.example.com ? Please can you explain why, what difference does it make to you?

jancurn avatar Aug 24 '22 09:08 jancurn

I using external free proxies without authorization - on tunnel, for example the browser loaded with proxy 127.0.0.1:8080 always and the tunnel changed on the fly...

anton-lsports avatar Aug 25 '22 06:08 anton-lsports

Hi Jan, do you have any updates?

anton-lsports avatar Aug 28 '22 07:08 anton-lsports

But why do you need the "anonymized" URL like http://127.0.0.1:8080, why don't you use the target free proxy URL? It just works too, no?

jancurn avatar Aug 29 '22 08:08 jancurn

My need is to open a browser with http://127.0.0.1:8080 as a tunnel for switching proxies on the fly. When I want to use some proxy I use the proxy-chain that way I can switch between proxies as shown below:

import * as Puppeteer from 'puppeteer';
import * as proxyChain from 'proxy-chain';
let newProxyUrl = null;
let page = null;
(async () => {
  const browser = await Puppeteer.launch({
    headless: false,
    args: [`--proxy-server=http://127.0.0.1:8080`], //the proxy is static, NOT CHANGED ANY MORE
  });
  page = await browser.newPage();
  //first time set proxy
  await switchProxy(
    'http://username:passwored@proxyExample:port'
  );
  await page.goto('https://ifconfig.me/');
})();
async function switchProxy(proxy) {
  console.log('switch IP to new one: ' + proxy);
  if (newProxyUrl !== null)
    await proxyChain.closeAnonymizedProxy(newProxyUrl, true);
  newProxyUrl = await proxyChain.anonymizeProxy({ url: proxy, port: 8080 });
  await page.goto('https://ifconfig.me/');

  console.log(newProxyUrl);
}
function randomProxy() {
  const proxyList = [
    // example for proxy WITH username and password (works good)
    'http://username:passwored@proxyExample:port',
    // example for proxy WITHOUT username and password (throw exception)
    'http://proxyExample:port',
  ];
  switchProxy(proxyList[Math.floor(Math.random() * proxyList.length)]);
}
//this will change the proxy every minute
setInterval(randomProxy, 15000);

In the code example as shown above you can see that the tunnel is loaded only if I use proxy with username and password.

and that because the tunnel is not longer open and you return the proxy string as is (as it was provided, without processing the proxy tunnel).

avihaizanaa avatar Aug 30 '22 09:08 avihaizanaa

Oh right, now I understand. Let us look into it. CC @szmarczak

jancurn avatar Aug 30 '22 09:08 jancurn

Perhaps we could add an option that would also anonymize password-less proxy URLs, but not sure whether it's not overkill, as the caller might decide this for themselves. "anonymization" might refer to also hiding proxy hostname and password, so logically this would be correct.

jancurn avatar Aug 30 '22 09:08 jancurn

Thanks you very much for the fast reply :) We are looking for the solution for the detailed scenario. Would love if you can update us for an estimation :)

avihaizanaa avatar Aug 30 '22 09:08 avihaizanaa

Hi @avihaizanaa! I believe that the best solution would be to use ProxyChain.Server like so:

let upstreamProxyUrl = 'http://proxy.example.com:2222';

const switchProxy = proxy => {
	upstreamProxyUrl = proxy;

	// Force browsers to update the connections in order not to use the old proxy anymore
	server.closeConnections();
};

const server = new ProxyChain.Server({
	port: 8000,
	prepareRequestFunction: () => {
		return {
			upstreamProxyUrl,
		};
	},
});

await server.listen();

This way you don't need to close & start the server over and over again.

szmarczak avatar Aug 31 '22 11:08 szmarczak

https://github.com/apify/proxy-chain/pull/296

anton-lsports avatar Sep 01 '22 09:09 anton-lsports

@anton-lsports Can you explain your comment a bit more please? I'm confused.

szmarczak avatar Sep 01 '22 15:09 szmarczak

Hi @szmarczak, We will test the solution you gave us, but in the mean time we would like if you can check the PR we send as a solution suggestion. https://github.com/apify/proxy-chain/pull/296 thanks!

avihaizanaa avatar Sep 04 '22 07:09 avihaizanaa

Hello, can you further comment on the Pull Request? And also comment what forceTunnel means in the code. Thanks

jirimoravcik avatar Feb 13 '23 15:02 jirimoravcik

Closing as @szmarczak's suggestion in https://github.com/apify/proxy-chain/issues/288#issuecomment-1232787186 should be enough for this usecase.

fnesveda avatar Mar 29 '23 12:03 fnesveda