hostname - Get host name in java -
i using jdk 8 weblogic server 12 r2c. application public facing , need host name of client. if client host name in list of allowed host names can access application, special features shown them. question how host name. tried below code , getting 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) @ java.net.inetaddress$2.lookupallhostaddr(inetaddress.java:928) @ java.net.inetaddress.getaddressesfromnameservice(inetaddress.java:1323) @ java.net.inetaddress.getallbyname0(inetaddress.java:1276) @ java.net.inetaddress.getallbyname(inetaddress.java:1192)
all above ip address sample dummy address taken 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 happens request may come proxies server, in case how domain name. tee above in filter code invoked every request.
Comments
Post a Comment