title: How to get Host name of ip address in android?
body: <p>I want to make a small android app that get ip addresses and host name from LAN network that are connected. I have a code that run great to get ip address in a LAN network which is connected but I don't know how to get host name of their ip addresses. Where I need to changing in code. Sorry for bad English.</p>
  
  <blockquote>
    <p>Here is my code for getting ip address in lan network </p>
  </blockquote>
  
  <pre><code>String connections = "";
      InetAddress host;
      try
      {
          host = InetAddress.getByName("192.168.1.1");
         byte[] ip = host.getAddress();
         for(int i = 1; i &lt;= 254; i++)
          {
              ip[3] = (byte) i;
              InetAddress address = InetAddress.getByAddress(ip);
  
              if(address.isReachable(100))
              {
  
  
                  System.out.println(address + " machine is turned on and can be pinged "+address.getCanonicalHostName());
                  connections+= address+"\n";
              }
              else if(!address.getHostAddress().equals(address.getHostName()))
              {
                  System.out.println(address + " machine is known in a DNS lookup");
                  System.out.println(address.getHostAddress()+"host Name:"+ address.getHostName());
              }
  
          }
          tv.setText(connections);
  
      }
      catch(UnknownHostException e1)
      {
          e1.printStackTrace();
      }
      catch(IOException e)
      {
          e.printStackTrace();
      }
  </code></pre>