ProxyMesh Blog

Control the IP Address of the ProxyMesh Proxy

30 April 2012

The ProxyMesh proxy server provides a few custom headers that you can use to control which IP address to use for each http request. If no headers are passed in, the default method of selecting an IP address is to randomly select from the available IP addresses.

The X-ProxyMesh-IP request header allows you specify exactly which IP address to use. For example, if you pass in the header X-ProxyMesh-IP: XXX.XXX.XXX.XXX then your request will appear to come from the IP address XXX.XXX.XXX.XXX. However, you can only specify one of the current outgoing IP addresses. If you specify any other IP address, you will get a 502: unknown IP address response.

To know which IP addresses are available, use the X-ProxyMesh-IP response header, which is included in every response you receive thru the proxy server. This header looks just like the request header, X-ProxyMesh-IP: XXX.XXX.XXX.XXX, and contains the IP address used to make your request. So you could make a single request thru the proxy server, extract the X-ProxyMesh-IP response header, and then include that as a request header in your next request in order to continue using that same IP address. You can verify that this process is working by comparing each X-ProxyMesh-IP request header to each X-ProxyMesh-IP response header.

The X-ProxyMesh-Prefer-IP request header works very much like the X-ProxyMesh-IP request header, but it will never return a 502 response. Instead, if you specify an unknown IP address, another IP address will be chosen, just as if you didn't include the header.

And finally, the X-ProxyMesh-Not-IP request header allows you to specify a comma list of IP addresses that you do not want to use for that request. For example, if you pass in a header that looks like X-ProxyMesh-Not-IP: XXX.XXX.XXX.XXX,YYY.YYY.YYY.YYY, then neither XXX.XXX.XXX.XXX nor YYY.YYY.YYY.YYY will be used, leaving you with the remaining IP addresses to randomly choose from. It is theoretically possible that you could exclude all available IP addresses with this header, in which case you will get a 503: no available IP addresses response.

These headers are exclusive, meaning that you should not combine them. Any custom header you pass in will only used by ProxyMesh proxy server, and will be removed before your request is passed on to the final site.