title: How to get all addresses Ip and mac of connected devices to local network using java
body: <p>I'm creating a java project that shows hostname , ip and mac address of connected devices using java . I use InetAddress but it only shows me the Ip's and hostname of connected computers without MAC and also can't see connected mobiles like Android devices.</p>
  
  <p>I tried almost every solution on StackOverFlow but none of theme seems to work</p>
  
  <pre><code>public class HostDiscovery
  {
      private String address;
      private int discoveryTimeout;
  
      HostDiscovery( String address,  int discoveryTimeout)
      {
         this.address = address;
         this.discoveryTimeout = discoveryTimeout;
      }
  
      public Future&lt;HostDiscoveryResult&gt; multithreadedHostDicovery(final ExecutorService exService){
          return exService.submit(() -&gt; {
              try
              {
                  String HostName = null;
                  String MacAddress = null;
                  boolean result = InetAddress.getByName(address).isReachable(discoveryTimeout);
                  InetAddress ip = InetAddress.getByName(address);
                   if (result)
                  {
  
                      HostName = InetAddress.getByName(address).getHostName();
                      if(HostName.endsWith(".mshome.net")){
                          HostName = HostName.replaceAll(".mshome.net", "");
                      }
                      MacAddress = getMacAddress(ip);
                  }
                  return new HostDiscoveryResult(address, result, HostName, MacAddress);
              } catch (SocketException ex)
              {
                  return new HostDiscoveryResult(address, false, null, null);
              }
          });
      }
  
  
  
     private static String getMacAddress(InetAddress ip) throws UnknownHostException {
          String address = null;
          try {
              NetworkInterface network = NetworkInterface.getByInetAddress(ip);
              byte[] mac = network.getHardwareAddress();
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i &lt; mac.length; i++) {
                  sb.append(String.format("%02X%s", mac[i], (i &lt; mac.length - 1) ? "-" : ""));
              }
              address = sb.toString();
  
          } catch (SocketException ex) {
  
              ex.printStackTrace();
  
          }
  
          return address;
      }
  
  
  
  
  }
  </code></pre>