How to read the client MAC Address using NetworkInterface in Java
<blockquote>
  <p>I have a code that reads the LocalHost Mac Address. 
  The code is being called from the Servlet or JSP.<br />
  But failed to read the address of REMOTE HOST or Client. 
  I am using the NetworkInterface class to implement the functionality.<br />
  One reason which I understand that its reading the localhost address is - able to Lookup the LocalHost address, but failed to lookup or do the reverse dns search on the Remote Host.
  <br /></p>
</blockquote>

<pre><code>    InetAddress addr = InetAddress.getByName(clientIP);
    NetworkInterface ni = NetworkInterface.getByInetAddress(addr);

            if (ni == null)
            {
                throw new SocketException("Cannot reach the host ##"+clientIP+"."); // Throws exception here for REMOTE Host or CLient
            }

    byte[] macAddrs = ni.getHardwareAddress();

    if (macAddrs == null) {
                throw new UnknownHostException("Host IP Adrress Lookup Failed...");
            }

            for (int k = 0; k &lt; macAddrs.length; k++) {
                String macValue = String.format("%02X%s", macAddrs[k], (k &lt; macAddrs.length - 1) ? "-" : "");
                macAddress.append(macValue);
            }
</code></pre>
