title: Client computer name in java
body: <p>I want to find client computer name in java. My applciation runs in intranet. so i am using below code </p>
  
  <pre><code>   public String findClientComputerName(HttpServletRequest request) {
      String computerName = null;
      String remoteAddress = request.getRemoteAddr();
      System.out.println("remoteAddress: " + remoteAddress);
      try {
          InetAddress inetAddress = InetAddress.getByName(remoteAddress);
          System.out.println("inetAddress: " + inetAddress);
          computerName = inetAddress.getHostName();
          System.out.println("computerName: " + computerName);
          if (computerName.equalsIgnoreCase("localhost")) {
              computerName = java.net.InetAddress.getLocalHost().getCanonicalHostName();
          } 
      } catch (UnknownHostException e) {
          log.error("UnknownHostException detected in StartAction. ", e);
      }
      if(StringUtils.trim(computerName).length()&gt;0) computerName = computerName.toUpperCase();
      System.out.println("computerName: " + computerName);
      return computerName;
  }
  </code></pre>
  
  <p>but sometimes i am getting host name properly but some time not. I am getting Correct IP. What may be the reason for this? Why  <code>inetAddress.getHostName();</code> is failing to give host name some time? Your help is very appriciated.</p>