title: Getting ip address instead of hostname from gethostbyname function from InetAddress class of java
body: <p>How is it possible to get the IP-Address from the <code>gethostbyname</code> function from the <code>InetAddress</code> class in java ? With the following code I am not getting the hostname from the local machine's ip adrress.</p>
  
  <pre><code>import java.net.InetAddress;
  
  class GetHost{
  
      public static void main(String args[])throws Exception{
  
          String hostIp=args[0];
          InetAddress addr = InetAddress.getByName(hostIp);
          String host = addr.getHostName();
          if(host.endsWith(".local"))
          {
              int lenght=host.length() ;
              System.out.print(""+host.substring(0,lenght-6));
  
          }
          else
              System.out.print(host);
  
      }
   }
  </code></pre>