<p>I would like to retrieve the ethernet address of the network interface that is used to access a particular website.</p>

<p>How can this be done in Java?</p>

<p><strong>Solution</strong> Note that the accepted solution of <code>getHardwareAddress</code> is only available in Java 6. There does not seem to be a solution for Java 5 aside from executing i(f|p)confing.</p>

[{'answer_id': 33966, 'author': 'Doug Miller', 'author_id': 3431280, 'author_profile': 'https://Stackoverflow.com/users/3431280', 'pm_score': 2, 'selected': False, 'text': '<p>You can get the address that connects to your ServerSocket using <a href="http://java.sun.com/javase/6/docs/api/java/net/NetworkInterface.html#getInetAddresses()" rel="nofollow noreferrer">http://java.sun.com/javase/6/docs/api/java/net/NetworkInterface.html#getInetAddresses()</a></p>\n\n<p>However if your client is connecting via a NAT, then you will get the address of the router and NOT the Ethernet address. If it is on your local network (via a hub/switch, no router with NAT) the it wil work as intended.</p>\n'}, {'answer_id': 33967, 'author': 'skolima', 'author_id': 3205, 'author_profile': 'https://Stackoverflow.com/users/3205', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://java.sun.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress%28%29" rel="noreferrer"> java.net.NetworkInterface.getHardwareAddress</a> (method added in Java 6)</p>\n\n<p>It has to be called on the machine you are interested in - the MAC is not transferred across network boundaries (i.e. LAN and WAN). If you want to make use of it on a website server to interrogate the clients, you\'d have to run an applet that would report the result back to you.</p>\n\n<p>For Java 5 and older I found code <a href="http://forums.sun.com/thread.jspa?messageID=3424868#4204392" rel="noreferrer">parsing output of command line tools on various systems</a>.</p>\n'}, {'answer_id': 2656092, 'author': 'StaxMan', 'author_id': 59501, 'author_profile': 'https://Stackoverflow.com/users/59501', 'pm_score': 2, 'selected': False, 'text': '<p>Actually, beyond other right answers (JDK 6; exec \'ifconfig\'), there are JNI-based libraries. <a href="http://jug.safehaus.org" rel="nofollow noreferrer">Java Uuid Generator (JUG) 2.0</a> has code for some platforms. This works on JDK 1.2 and above at least (maybe 1.1 even)</p>\n'}]
['https://Stackoverflow.com/questions/33960', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/338/']