0

We recently needed to implement a headless browser (used Selenium). It was required to send requests from different Ip addresses without restarting the driver, but after searching the Internet for information, I did not find a way to do this without restarting.

A few days later we found a solution, I want to share it by answering my own question.

We have a server with a set of external ip. We will raise the proxy to our own on the locale.

1 Answers1

0

We used 3Proxy to run our proxies.

Variation 1: When initializing the driver, we can choose a local ip and port as a proxy. Thus, to change the ip, we only need to restart the proxy on this port, which will refer to another ip.

Variation 2: If you want to use a proxy that is not raised by you, then you can modify the solution, create a proxy chain.

Your browser will access the local address where you will raise a proxy that will forward the request to the desired proxy. So to change the proxy, you will need to restart the local proxy, which performs the function of a router between your ChromeDriver and the target proxy (it may be a free proxy that is not connected to you in any way), which remains unchanged.

It's like with the arrows on the railway.

Examples:

3ProxyConfig:

auth none
log
internal 127.0.0.1
external 'your local address or open address'
proxy -n

Default ChromeOptions:

public ChromeOptions CreateDefaultOptions()
{
    var chromeOptions = new ChromeOptions();
    chromeOptions.AddArguments("--headless");
    chromeOptions.AddArguments("--disable-gpu");
    chromeOptions.AddArguments("--no-sandbox");                                    
    chromeOptions.AddAdditionalChromeOption("useAutomationExtension",false);
    chromeOptions.AddArgument("ignore-certificate-errors");

    return chromeOptions;
}

To form is necessary to add --proxy-server parametr

private void InitProxyByInternalIp(IPAddress internalAddress, int port)
{
    Options.AddArgument($"--proxy-server={internalAddress}:{port}");
}