JDK-6763420 : NetworkInterface.getNetworkInterfaces() returns duplicate
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6,6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2008-10-24
  • Updated: 2011-02-16
  • Resolved: 2009-04-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java 6 

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]

A DESCRIPTION OF THE PROBLEM :
The java.net.NetworkInterface.getHardwareAddress() method within Java 6 under Windows Vista produces duplicate MAC addresses (same MAC for Wireless and Ethernet in the scenario detailed within this Bug report).

This is not a problem under Windows XP - the sample code works successfully.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
ipconfig /all on Windows Vista reveals two Adapters:

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Atheros AR5007EG Wireless Network Adapter

   Physical Address. . . . . . . . . : 00-15-AF-57-E8-09

Ethernet adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Realtek RTL8139/810x Family Fast Ethernet
 NIC
   Physical Address. . . . . . . . . : 00-1D-60-0F-FB-BE


However, the java.net.NetworkInterface.getHardwareAddress() method of produces the same MAC address for both adapters:

Count : 7
Display Name: Realtek RTL8139/810x Family Fast Ethernet NIC
Name        : eth2
MAC ADDRESS : 00-1D-60-0F-FB-BE

Count : 8
Display Name: Atheros AR5007EG Wireless Network Adapter
Name        : net2
MAC ADDRESS : 00-1D-60-0F-FB-BE

*** THE CODE WORKS SUCCESSFULLY UNDER WINDOWS XP, JUST NOT VISTA ***

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Count : 7
Display Name: Realtek RTL8139/810x Family Fast Ethernet NIC
Name        : eth2
MAC ADDRESS : 00-1D-60-0F-FB-BE

Count : 8
Display Name: Atheros AR5007EG Wireless Network Adapter
Name        : net2
MAC ADDRESS : 00-15-AF-57-E8-09
ACTUAL -
Count : 7
Display Name: Realtek RTL8139/810x Family Fast Ethernet NIC
Name        : eth2
MAC ADDRESS : 00-1D-60-0F-FB-BE

Count : 8
Display Name: Atheros AR5007EG Wireless Network Adapter
Name        : net2
MAC ADDRESS : 00-1D-60-0F-FB-BE

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error is the duplicate MAC address

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
        try {
		Enumeration<NetworkInterface> netInt = NetworkInterface.getNetworkInterfaces();
 
		int count = 0;
			
		while (netInt.hasMoreElements()) {

			System.out.println("Count : "+count);
				
			NetworkInterface networkInterface = (NetworkInterface) netInt.nextElement();

			System.out.println("Display Name: "+networkInterface.getDisplayName());
			System.out.println("Name        : "+networkInterface.getName());

			if(networkInterface.getHardwareAddress() != null) {
				byte[] b = networkInterface.getHardwareAddress();
				System.out.println("MAC ADDRESS : "+createMACAddress(b));
			}
			count++;
 
			System.out.println();
		}

	} catch (SocketException e) {
		e.printStackTrace();
	}


	public static String createMACAddress(byte[] bytes) {
		String macAddress = "";
		
		for(int i = 0; i < bytes.length; i++) {
		  String temp = Integer.toHexString(bytes[i] & 0xff);
		  temp = temp.length() > 1 ? temp : "0" + temp;
		  macAddress += temp.toUpperCase();
		  if(i<bytes.length-1) {
			  macAddress += "-";
		  }
		}
		
		return macAddress;
	}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Workaround is to use Runtime.exec("ipconfig /all") and parse into an InputStream

		Process p = Runtime.getRuntime().exec("ipconfig /all");
		InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
 
...

Read from the stream into a string, then search through for MAC addresses

			String ipConfigText = "Physical Address. . . . . . . . . : ";

This produces the correct results, but is only valid for Windows.

Comments
EVALUATION This should have been closed last week, am updating now.
28-04-2009

EVALUATION I can't reproduce this. I am seeing distinct MAC addresses from interfaces (that have distinct MAC addresses). I'll mark incomplete, but if more info cannot be provided, will have to close.
26-03-2009