Skip to content

Commit

Permalink
#257 extract own getNetworkInterfaces() that does reversal on non-Win…
Browse files Browse the repository at this point in the history
…dows platforms
  • Loading branch information
angryziber committed Oct 27, 2020
1 parent e17fb09 commit d4c77d3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/net/azib/ipscan/util/InetAddressUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.list;
import static java.util.Collections.reverse;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
Expand Down Expand Up @@ -163,9 +162,9 @@ public static boolean isLikelyBroadcast(InetAddress address) {
public static InterfaceAddress getLocalInterface() {
InterfaceAddress anyAddress = null;
try {
List<NetworkInterface> interfaces = list(getNetworkInterfaces()).stream()
List<NetworkInterface> interfaces = getNetworkInterfaces().stream()
.filter(i -> i.getParent() == null && !i.isVirtual()).collect(toList());
if (!Platform.WINDOWS) reverse(interfaces);

for (NetworkInterface networkInterface : interfaces) {
for (InterfaceAddress ifAddr : networkInterface.getInterfaceAddresses()) {
anyAddress = ifAddr;
Expand All @@ -180,4 +179,10 @@ public static InterfaceAddress getLocalInterface() {
}
return anyAddress;
}

public static List<NetworkInterface> getNetworkInterfaces() throws SocketException {
List<NetworkInterface> interfaces = list(NetworkInterface.getNetworkInterfaces());
if (!Platform.WINDOWS) reverse(interfaces);
return interfaces;
}
}

0 comments on commit d4c77d3

Please sign in to comment.