JDK-8022639 : NetworkInterface.getNetworkInterfaces() returns incorrect mac adress (getHardwa)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u25
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • Submitted: 2013-07-31
  • Updated: 2013-08-08
  • Resolved: 2013-08-08
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)

ADDITIONAL OS VERSION INFORMATION :
Windows 7 Professional x64 sp1
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Wireless Lan + Wired Lan

A DESCRIPTION OF THE PROBLEM :
same Bug as:
JDK-6709430 - Unable to detect MAC address in Windows Vista

The java.net.NetworkInterface.getHardwareAddress() method within Java 6+7 under MY Windows 7 returns a wrong MAC addresses for a wired lan (same MAC as for wireless lan adapter).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Java function NetworkInterface.getNetworkInterfaces().nextElement().getHardwareAddress() returns this:
Display Name: Intel(R) 82579LM Gigabit Network Connection
Name        : eth4
MAC ADDRESS : 10-0B-A9-94-1F-9C

Windows command line return:
Ethernet-Adapter LAN-Verbindung:

   Verbindungsspezifisches DNS-Suffix:
   Beschreibung. . . . . . . . . . . : Intel(R) 82579LM Gigabit Network Connecti
on
   Physikalische Adresse . . . . . . : F0-DE-F1-CB-ED-3D


Reference info from windows command line: ipconfig /all

Windows-IP-Konfiguration

   Hostname  . . . . . . . . . . . . : test520
   Prim??res DNS-Suffix . . . . . . . :
   Knotentyp . . . . . . . . . . . . : Hybrid
   IP-Routing aktiviert  . . . . . . : Nein
   WINS-Proxy aktiviert  . . . . . . : Nein

Ethernet-Adapter LAN-Verbindung:

   Verbindungsspezifisches DNS-Suffix:
   Beschreibung. . . . . . . . . . . : Intel(R) 82579LM Gigabit Network Connecti
on
   Physikalische Adresse . . . . . . : F0-DE-F1-CB-ED-3D
   DHCP aktiviert. . . . . . . . . . : Ja
   Autokonfiguration aktiviert . . . : Ja
   IPv4-Adresse  . . . . . . . . . . : 11.37.10.86(Bevorzugt)
   Subnetzmaske  . . . . . . . . . . : 255.255.255.0
   Lease erhalten. . . . . . . . . . : Mittwoch, 31. Juli 2013 09:31:06
   Lease l??uft ab. . . . . . . . . . : Montag, 5. August 2013 09:31:05
   Standardgateway . . . . . . . . . : 11.37.10.2
   DHCP-Server . . . . . . . . . . . : 11.37.10.2
   DNS-Server  . . . . . . . . . . . : 8.8.8.8
                                       11.37.30.11
                                       11.37.5.150
   NetBIOS ??ber TCP/IP . . . . . . . : Aktiviert

Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung 2:

   Medienstatus. . . . . . . . . . . : Medium getrennt
   Verbindungsspezifisches DNS-Suffix:
   Beschreibung. . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
   Physikalische Adresse . . . . . . : 10-0B-A9-94-1F-9D
   DHCP aktiviert. . . . . . . . . . : Ja
   Autokonfiguration aktiviert . . . : Ja

Drahtlos-LAN-Adapter Drahtlosnetzwerkverbindung:

   Verbindungsspezifisches DNS-Suffix:
   Beschreibung. . . . . . . . . . . : Intel(R) Centrino(R) Advanced-N 6205
   Physikalische Adresse . . . . . . : 10-0B-A9-94-1F-9C
   DHCP aktiviert. . . . . . . . . . : Ja
   Autokonfiguration aktiviert . . . : Ja
   IPv4-Adresse  . . . . . . . . . . : 11.37.10.90(Bevorzugt)
   Subnetzmaske  . . . . . . . . . . : 255.255.255.0
   Lease erhalten. . . . . . . . . . : Mittwoch, 31. Juli 2013 10:06:18
   Lease l??uft ab. . . . . . . . . . : Montag, 5. August 2013 12:23:45
   Standardgateway . . . . . . . . . : 11.37.10.2
   DHCP-Server . . . . . . . . . . . : 11.37.10.2
   DNS-Server  . . . . . . . . . . . : 8.8.8.8
                                       11.37.30.11
                                       11.37.5.150
   NetBIOS ??ber TCP/IP . . . . . . . : Aktiviert
....


Java Program produces:

....
Count : 12
Display Name: Intel(R) 82579LM Gigabit Network Connection
Name        : eth4
MAC ADDRESS : 10-0B-A9-94-1F-9C

Count : 13
Display Name: Intel(R) Centrino(R) Advanced-N 6205
Name        : net5
MAC ADDRESS : 10-0B-A9-94-1F-9C

Count : 14
Display Name: Microsoft Virtual WiFi Miniport Adapter
Name        : net6
MAC ADDRESS : 10-0B-A9-94-1F-9C
.....




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
....
Count : 12
Display Name: Intel(R) 82579LM Gigabit Network Connection
Name        : eth4
MAC ADDRESS : F0-DE-F1-CB-ED-3D
.....



REPRODUCIBILITY :
This bug can be reproduced always.

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

public class WrongMacAddress {

public static void main(String[] args) throws SocketException {

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();
}
}

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 ----------
Comments
Duplicate of 8021380.
08-08-2013