Well, you are in the 192.168.* net so perhaps it doesn't have a name that can be looked up?
The are many problems with that code.
At the most fundamental level, getLocalName() returns the name of the server interface through which the request was received.
localis local to the server. From the server, the browser is the
Even then (if you tried to do the same with the remote host), you're asking the DNS servers available to the server to resolve an IP that's defined on the client. There are multiple problems with this: if private ranges are used, they are not unique at all. And in this case the client does use one. Then the OS matters, as well as whether there are multiple cards, each with its own host name. But all this is moot because the server (the HttpServletRequest object is on the server side) does not know the host name of the machine on which the HTTP request originates. Packets that reach the server may have been passed through proxies and so on. The
remote hostseen by the server is not necessarily the
origin. The network layer thus cannot tell you that information and the HTTP protocol does not send the local machine name (for a number of reasons, security included).
AFAIK, there are no portable solutions for what you want.
Thank you, Nicklas and Jean. Very useful information and it's good to know that I wasn't losing my mind -- that the task at hand is impossible. I'll stick with IP address.