title: Get MAC Address of System in Java
body: <p>I need to get the mac address of the system running the program. But I am not able to do that.</p>
  
  <p>I am writing following code:</p>
  
  <pre><code>public class App{
  
         public static void main(String[] args){
  
          InetAddress ip;
          try {
  
              ip = InetAddress.getLocalHost();
              System.out.println("Current IP address : " + ip.getHostAddress());
  
              NetworkInterface network = NetworkInterface.getByInetAddress(ip);
  
              byte[] mac = network.getHardwareAddress();
  
              System.out.print("Current MAC address : ");
  
              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) ? "-" : ""));        
              }
              System.out.println(sb.toString());
  
          } catch (UnknownHostException e) {
  
              e.printStackTrace();
  
          } catch (SocketException e){
  
              e.printStackTrace();
  
          }
  
         }
  
      }
  </code></pre>
  
  <p>And I am getting following results:</p>
  
  <pre><code> Current IP address : 14.96.192.202
   Current MAC address : 
  </code></pre>
  
  <p>I am not getting the MAC Address it is blank.</p>
  
  <p>I saw this example from <a href="http://www.mkyong.com/java/how-to-get-mac-address-in-java/" rel="noreferrer">here</a></p>