How to get host name of connected client in java?

I am writing a server application and I want to get the host name of the connecting client, how will I do this in java?

clientSocket.getInetAddress().getHostName() continues to give me an IP address instead of a host name, what's wrong?

where ClientSocket is an SSLSocket or Socket.

+4
source share
1 answer

Try getCanonicalHostName() instead, but read the Javadoc as this is not guaranteed. (You are limited to what is registered in DNS, etc.)

+6
source

Source: https://habr.com/ru/post/1387682/


All Articles