Set client IP of HttpURLConnection

J

js

Hello,

I have the following problem:
On one of our servers runs a web application which connects through a
HttpUrlConnection to another server and sends requests. Our server has
two IP addresses. The other server only accepts requests from one of
those. But our server uses the other one as default...

The following options are not possible for different reasons:
- to write our own HttpUrlConnection class
- to change the default IP of our server
- to change the configuration of the other server
- to fiddle with the IP of outgoing packets via NAT or something

Does anyone know how to set the source IP of the request from Java?

Greetings and thanks in advance
Jan Strube
 
G

Gordon Beaton

- to fiddle with the IP of outgoing packets via NAT or something

The "wrong" outgoing interface is chosen because it matches a routing
rule, probably the default route of the connecting machine.

You could set up a static route to the other server that specifies the
correct local interface, no need for NAT.

/gordon

--
 
E

Esmond Pitt

It can't be done in Java. AFAIK an HTTP request doesn't even contain it,
it's in the TCP packets, and you can't control that.

You will have to fix the fussy server.
 
J

js

I've got the solution:
With the Apache Commons HttpClient it is possible to set the local
address.

Greetings
Jan
 
M

Manivannan Palanichamy

Hello,

I have the following problem:
On one of our servers runs a web application which connects through a
HttpUrlConnection to another server and sends requests. Our server has
two IP addresses. The other server only accepts requests from one of
those. But our server uses the other one as default...

The following options are not possible for different reasons:
- to write our own HttpUrlConnection class
- to change the default IP of our server
- to change the configuration of the other server
- to fiddle with the IP of outgoing packets via NAT or something

Does anyone know how to set the source IP of the request from Java?

Greetings and thanks in advance
Jan Strube

looks like a puzzle in java :) Those 4 steps are the possible ways of
finding a solution to this prob.
anyway, you could set the source ip of packet in using Jpcap -- Java
packet filtering libraries. But, that will
require highest user login, such as root in linux or administrator in
windows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top