In my code, I try to fetch all the network adapters. The "disconnected" network adapters are kept but those "disabled" ones need to be filtered out. (The "disabled" ones are those with a little arrow in the screenshot below).
Currently, I'm using java.net.NetworkInterface#getNetworkInterfaces and iterate through the returned java.net.NetworkInterface objects. However, it doesn't have a method to check if the network interface is "disabled".
I guess there might be a way to read the NIC status from the registry, but I couldn't find it after googling for hours. Is there any other way to do it?
My environment:
Microsoft Windows Server 2016 Datacenter
JDK 8
The investigation I have made so far
In the JDK native code, if “IPv6 Available” - it calls Java_java_net_NetworkInterface_getMacAddr0_XP https://github.com/frohoff/jdk8u-jdk/blob/master/src/windows/native/java/net/NetworkInterface.c#L1007 . This calls getAdapter which calls Windows' GetAdaptersAddresses. The flags are GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_INCLUDE_PREFIX. Since it does NOT include the GAA_FLAG_INCLUDE_ALL_INTERFACES flag, it does NOT include the hidden interface.
However, if NOT “IPv6 Available” - it calls getIF , which eventually calls GetIfTable that returns all interfaces (with mac addresses) INCLUDING hidden interface.
So it behaves differently depending on whether the IPv6 is available, we just have no way to control it.