Reputation: 4223
I'm writing a server application and I want to get the hostname of the connecting client, how would I go about doing it in java?
clientSocket.getInetAddress().getHostName()
keeps giving me the IP address instead of the hostname, what's wrong?
where ClientSocket
is an SSLSocket
or Socket.
Upvotes: 6
Views: 9052
Reputation: 28687
Try getCanonicalHostName()
instead - but read the Javadoc, as this is not guaranteed. (You're limited to what is registered in DNS, etc.)
Upvotes: 7