title: Remote PC name and IP using Java
body: <p>I am trying to get the remote PC names and IP address connected in the network using Java. I am able to get the IP's but can't get the names of the devices. I am attaching the code for reference. </p>
  
  <p><strong>Java Code:</strong> </p>
  
  <pre><code>import java.io.IOException;
  import java.net.InetAddress;
  
  public class findIP {
  
  
      public static void main(String[] args) throws IOException {
  
          InetAddress localhost = InetAddress.getLocalHost();
          // this code assumes IPv4 is used
          byte[] ip = localhost.getAddress();
          String N = localhost.getHostName();
  
          for (int i = 1; i &lt;= 254; i++)
          {
              ip[3] = (byte)i;
              InetAddress address = InetAddress.getByAddress(ip);
              InetAddress name = InetAddress.getByName(N);
          if (address.isReachable(1000))
          {
              System.out.println(address+"            " +"Device Name: "+name);
          }
  </code></pre>