shawn
shawn

Reputation: 4223

How do I get the hostname of a connected client in java?

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

Answers (1)

ziesemer
ziesemer

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

Related Questions