title: How to get IP address and names of all devices in local network on Android
body: <p>I want to see all the connected devices on my network with java, but I can't get it working. I have attached some screenshots below of how I want it to be output. I would like to have the name (for example "TP Link Router" or "Nexus 5X") and the IP address.</p>
  
  <p>I have searched a lot on google and stackoverflow, but nothing seemed to work for me. Even GitHub has no effective code. I tried searching for UPnP, Local Area Network, subnets, etc, but found nothing.</p>
  
  <pre><code>InetAddress localhost = InetAddress.getLocalHost();
  byte[] ip = localhost.getAddress();
  for (int i = 1; i &lt;= 254; i++) {
      ip[3] = (byte)i;
      InetAddress address = InetAddress.getByAddress(ip);
      if (address.isReachable(1000)) {
          System.out.println(address + address.getHostAddress() + address.getAddress() + address.getHostName() + address.getCanonicalHostName());
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0DCY6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0DCY6.png" alt="Example 1"></a>
  <a href="https://i.stack.imgur.com/wz3lW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wz3lW.png" alt="Example 2"></a></p>
  
  <p>I did in fact find a duplicate (sort of) question, but it hasn't been answered for over a year. <a href="https://stackoverflow.com/questions/29331227/how-can-i-get-the-name-and-ip-of-all-devices-in-my-network-or-get-the-router-ip">Source</a></p>