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.
Try getCanonicalHostName()
instead - but read the Javadoc, as this is not guaranteed. (You're limited to what is registered in DNS, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With