Java – Host IP Address 0:0:0:0:0:0:0:1 on Servlet


I am trying to get the user Host, IP, and Port using:


But I am getting:

Host: 0:0:0:0:0:0:0:1
IP: Address null
Port: 51111

How do I get the correct IP address, noting that our network IP start with 10.100.x.x

Many thanks.

Best Solution

If you are using the localhost in your request URI, then the IPv6 is 0:0:0:0:0:0:0:1. Instead of using localhost, use your IPv4 in your request URI to get the correct IP.