Controlling IP Addresses of Requests

By default, the proxy servers will choose a random IP for every request. But you can modify that behavior using custom headers.

X-ProxyMesh-IP Headers

The following custom headers let you specify exact IPs. In order to use them, you must get IP values from the X-ProxyMesh-IP response header. You can find more details on the X-ProxyMesh custom headers at  Proxy Server Request & Response Headers. Keep in mind that for HTTPS requests, custom headers must be handled differently. For details, please see:

X-ProxyMesh-IP

Use this header when you want to specify a particular IP for a request. This IP should come from the  X-ProxyMesh-IP response header of a previous request. If the IP is no longer available, you will get a 502 error code with the X-ProxyMesh-IP-Not-Found response header.

X-ProxyMesh-Prefer-IP

Use this header when you want to use a specific IP for a request, but you also want the request to succeed even if the IP is no longer available. This is like the  X-ProxyMesh-IP header, but when an IP is not available, a random IP is chosen instead. You can tell when this happens by comparing the X-ProxyMesh-IP response header to the IP you sent with the X-ProxyMesh-Prefer-IP header. If they are different, then the IP you tried to use is no longer available.

X-ProxyMesh-Not-IP

Use this header to exclude a specific IP from the available choices. An IP other than the excluded IP will be chosen at random.

You can also send a comma-separated-values list of IPs to exclude multiple IPs. You will get a  502 error code if no more IPs are available, after excluding the IPs sent in the header.

Authentication Header String

Another method for controlling the IP addresses is to use a random string in the Proxy-Authorization header. Then,  instead of passing in an encoded username:password to the authentication header, you pass in username:string:password, where string is a random string that you generate. As long as you keep using the same string – assuming the outgoing IP is available – the proxy server will choose that same outgoing IP. If the IP is no longer available, then a new IP will be chosen by the proxy server, and will be used for subsequent requests with the same string.

Most client libraries support the  Basic access authentication method, which means the only change required in your code is to join the string to your username when providing the header value. However, for HTTPS requests, only some libraries support sending the Proxy-Authorization header with the initial CONNECT, such as  Python requests. Other client libraries may require custom code to make the Proxy-Authorization header work for HTTPS requests. For additional details, please see Proxy Server Request & Response Headers.

Still need help? Contact Us Contact Us