Reputation: 2070
I am using LittleProxy which implements Netty . I am trying to return the IP address and port of the source of an HTTP request. I use the getRemoteAddress method, but the returned port is always different. It seems to add up after every request? I must be missing some insight here.
After some searching, I tried downcasting it to an InetSocketAddress. But the results are the same:
private void processRequest(final ChannelHandlerContext ctx,
final MessageEvent me) {
final HttpRequest request = (HttpRequest) me.getMessage();
//THOMAS EDIT FOR OUTPUT REMOTE ID AND PORT
InetSocketAddress inetAddr = (InetSocketAddress)me.getRemoteAddress();
System.out.println("Source IP: " + inetAddr.getAddress());
System.out.println("Source Port: " + inetAddr.getPort());
Upvotes: 0
Views: 1891
Reputation: 15768
Netty behaves like a Gateway or NAT. the IpAddress and Ports it give are its own port numbers.
what you can try is to get the HTTPHeader X-Forwarded-For
Option 2:
use ChannelHandlerContext instead of MessageEvent
ctx.getChannel().getRemoteAddress();
Upvotes: 2