Reputation: 451
I am trying to get the list of network connections in Windows platform using Java. I am able to get the network adapters with the following code
Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
ArrayList<NetworkInterface> interfaces = new ArrayList<>(Collections.list(interfaceList));
for (NetworkInterface aInterface : interfaces) {
if (aInterface.isLoopback() ||
aInterface.isVirtual())
continue;
System.out.println(aInterface.getName() + ": " + aInterface.isUp());
}
But this is not what I am looking for. This gives me a very long list of network interfaces. In windows, when you go to Network Connections window, you will probably get one Wireless connection, one network connections and a Bluetooth if you have the adapter. This is the list I want to retrieve in Java.
Thanks.
Upvotes: 1
Views: 876
Reputation: 6289
Add ! aInterface.isUp()
to the condition.
This will reduce the list to active interfaces only.
Upvotes: 1