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.
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.
- duplicates
-
JDK-6709430 Unable to detect MAC address in Windows Vista
- Closed