-1

I have an android app that makes a simple REST call to my backend server (Google App Engine [GAE]). On my GAE, I am trying to extract the IPv4 address of the connection and I always get a IPv6 address.

I'm using this to extract the ipAddress. In addition, I have checked that all functions from ClientInfo return either NULL or IPv6 address.

Any suggestions?

ip = headers.getFirstValue("X-FORWARDED-FOR");  
if (ip == null || ip.equals("")) {  
    ClientInfo clientInfo = request.getClientInfo();
    ip = clientInfo.getAddress();
}
else
{
    ClientInfo clientInfo = request.getClientInfo();
    LOG.info("X-FORWARDED-FOR IP:"+ip+" Other IP:"+clientInfo.getAddress());
}
Pankaj
  • 7,908
  • 6
  • 42
  • 65
Farhan Syed
  • 336
  • 3
  • 15

1 Answers1

1

A connection is either IPv4 or IPv6. If the connection comes in over IPv6 then there is no IPv4 address to know. If the connection from the front end load balancers to your GAE instance is IPv6 then that's what it is and you'll have to deal with it.

These days you can no longer assume that there is IPv4. Some parts of the internet are IPv6-only. The Facebook data centres were the first large scale example but Google is a big IPv6 supporter so I wouldn't be surprised to see something similar there.

Sander Steffann
  • 9,509
  • 35
  • 40