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}");
}