I'm working on a project that have the following need:
- use source ip address A to access http service S on Remote Server XX.YY.ZZ.WW
- use source ip address B to access http service T on Remote Server XX.YY.ZZ.WW(same as above)
XX.YY.ZZ.WW is a host I have no control of.
My server is configured with both IP A and IP B on the same Ethernet Interface. My project uses Apache HttpClient. It can be changed to something else if necessary.
Based on my TCP/IP knowledge, this is very easy. As long as I own the IP, I should be able to change the source IP address to whatever I want. But after all, I'm not manipulating IP packet directly. And I have no idea how this can be done with HttpClient.
You just need to tell HttpClient which network interface to use. You can do this with a connection property:
check out section 2.4 of the docs for a full description.
final DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(IP_ADDRESS));