Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 615
shawn Avatar asked Dec 23 '11 06:12

shawn


1 Answers

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

like image 98
ziesemer Avatar answered Oct 10 '22 20:10

ziesemer