JDK-8025532 : NetworkInterface.getHardwareAddress() returns same value for all NIFs
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u25,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • Submitted: 2013-09-20
  • Updated: 2013-09-27
  • Resolved: 2013-09-27
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

But happens also on:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b97)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b39, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
This network adapters are installed (ipconfig /all):
# Intel(R) 82579LM Gigabit Network Connection
# VirtualBox Host-Only Ethernet Adapter
# Check Point Virtual Network Adapter For Endpoint VPN Client
# PdaNet Broadband Adapter


A DESCRIPTION OF THE PROBLEM :
All NetworktInterfaces retrieved by NetworkInterfaces.getNetworkInterfaces() return the same hardware address (getHardwareAddress()), which is always one of the "real" Mac addresses of the existing network interfaces.
Which one depends on the VM.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
# Get all NetworkInterfaces using NetworkInterface.getNetworkInterfaces()
# Iterate over them
# Print out the MAC address calling NetworkInterface#getHardwareAddress() if it is not null

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should output the (different) Mac addresses of all available network interfaces/cards. (see ipconfig /all)
ACTUAL -
The program prints the same address for all network interfaces found.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;

public class ListMACs {
public static void main(String[] args) throws SocketException {
for (NetworkInterface ni : Collections.list(NetworkInterface
.getNetworkInterfaces())) {
if (ni.getHardwareAddress() != null) {
System.out.println(ni.getDisplayName() + ": " + ni.getHardwareAddress());
}
}
}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Call the windows-specific command "ipconfig /all", parse the output and extract the Mac-addresses from there. Not very convenient...
Comments
duplicates https://bugs.openjdk.java.net/browse/JDK-8021372
27-09-2013

Yes, I'm closing it as a duplicate. Thanks!
27-09-2013

If it is truly a duplicate of 8021372, then it should be closed as such. If a backport is required then 8021372 should be used as a bug number.
26-09-2013

I could reproduce the bug, though I needed to slightly modify the reproducer code. ------------------------------- import java.net.NetworkInterface; import java.net.SocketException; import java.util.Collections; public class ListMACs { public static void main(String[] args) throws SocketException { for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (ni.getHardwareAddress() != null) { byte[] ha = ni.getHardwareAddress(); System.out.print(ni.getDisplayName() + String.format(": %02X-%02X-%02X-%02X-%02X-%02X\n", ha[0] & 0xff, ha[1] & 0xff, ha[2] & 0xff, ha[3] & 0xff, ha[4] & 0xff, ha[5] & 0xff)); } } } } ------------------------------- In my case this program printed: Intel(R) 82579LM Gigabit Network Connection: 00-05-9A-3C-7A-00 Intel(R) Centrino(R) Advanced-N 6205: 00-05-9A-3C-7A-00 Bluetooth Device (Personal Area Network): 00-05-9A-3C-7A-00 Cisco AnyConnect VPN Virtual Miniport Adapter for Windows x64: 00-05-9A-3C-7A-00 VirtualBox Host-Only Ethernet Adapter: 00-05-9A-3C-7A-00 Microsoft Virtual WiFi Miniport Adapter: 00-05-9A-3C-7A-00 while ipconfig gives following: Cisco AnyConnect VPN Virtual Miniport Adapter for Windows x64: 00-05-9A-3C-7A-00 Microsoft Virtual WiFi Miniport Adapter: 60-67-20-6D-20-7D Bluetooth Device (Personal Area Network): E0-06-E6-BC-A2-31 Intel(R) Centrino(R) Advanced-N 6205: 60-67-20-6D-20-7C Intel(R) 82579LM Gigabit Network Connection: 00-21-CC-CE-69-60 VirtualBox Host-Only Ethernet Adapter: 08-00-27-00-04-48
26-09-2013