title: Get mac address in Java using getHardwareAddress non-deterministic
body: <p>I was having a problem to get the mac address of a machine, which was solved in <a href="https://stackoverflow.com/questions/6164167/get-mac-address-on-local-machine-with-java">this question</a> using the follow code:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("getmac /fo csv /nh"); 
  java.io.BufferedReader in = new java.io.BufferedReader(new  java.io.InputStreamReader(p.getInputStream())); 
  String line; 
  line = in.readLine();         
  String[] result = line.split(","); 
  
  System.out.println(result[0].replace('"', ' ').trim()); 
  </code></pre>
  
  <p>However, I would like to know why this code is not working. Every time it reads the MAC address it returns a different value. First I thought it was because getHash, maybe using a timestamp I dont know...  But even removing it the result changes.</p>
  
  <p>Code</p>
  
  <pre><code>    public static byte[] getMacAddress() {
          try {
              Enumeration&lt;NetworkInterface&gt; nwInterface = NetworkInterface.getNetworkInterfaces();
              while (nwInterface.hasMoreElements()) {
                  NetworkInterface nis = nwInterface.nextElement();
                  if (nis != null) {
                      byte[] mac = nis.getHardwareAddress();
                      if (mac != null) {
                          /*
                           * Extract each array of mac address and generate a
                           * hashCode for it
                           */
                          return mac;//.hashCode();
                      } else {
                          Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Address doesn't exist or is not accessible");
                      }
                  } else {
                      Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Network Interface for the specified address is not found.");
                  }
                  return null;
              }
          } catch (SocketException ex) {
              Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
          }
          return null;
      }
  }
  </code></pre>
  
  <p>Output example (i'm printing directly from byte array, but its enough to see that different i think)</p>
  
  <pre><code>[B@91cee
  [B@95c083
  [B@99681b
  [B@a61164
  [B@af8358
  [B@b61fd1
  [B@bb7465
  [B@bfc8e0
  [B@c2ff5
  [B@c8f6f8
  [B@d251a3
  [B@d6c16c
  [B@e2dae9
  [B@ef5502
  [B@f7f540
  [B@f99ff5
  [B@fec107
  </code></pre>
  
  <p>Thanks in advance</p>