Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8025532

NetworkInterface.getHardwareAddress() returns same value for all NIFs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7u25, 8
    • core-libs

      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...

            igerasim Ivan Gerasimov
            igerasim Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: