I am using jdk 8 with weblogic server 12 R2c. My application is public facing and i need to get the host name of the client. If the client host name is in the list of allowed host names which can access the application, then some special features are shown to them. Now my question is how to get the host name. I tried the below code and I am getting the following errors:
Errors:
- java.net.UnknownHostException: 234:343:343f:d1d34:a34:c%c3:45263:ab3c, 449.6.087.678: invalid IPv6 address
java.net.UnknownHostException: 14.5.254.458, 65.15.5.15: unknown error.
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) at java.net.InetAddress.getAllByName0(InetAddress.java:1276) at java.net.InetAddress.getAllByName(InetAddress.java:1192)
All the above IP address are sample dummy address which taken from my server log.
String ipAdr = request.getHeader("X-FORWARDED-FOR");
if (ipAdr == null) {
ipAdr = request.getRemoteAddr();
}
InetAddress addr = null;
String host = null;
if (ipAddress != null) {
addr = InetAddress.getByName(ipAdr);
host = addr.getHostName();
}
It so happens the request may come from proxies server, in that case how to get the domain name. Tee above is in the filter code which is invoked for every request.