use of java.net.InterfaceAddress in project cxf by apache.
the class WSDiscoveryClientTest method findIpv4Interface.
static NetworkInterface findIpv4Interface() throws Exception {
Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
List<NetworkInterface> possibles = new ArrayList<>();
while (ifcs.hasMoreElements()) {
NetworkInterface ni = ifcs.nextElement();
if (ni.supportsMulticast() && ni.isUp()) {
for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
if (ia.getAddress() instanceof java.net.Inet4Address && !ia.getAddress().isLoopbackAddress() && !ni.getDisplayName().startsWith("vnic")) {
possibles.add(ni);
}
}
}
}
return possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
}
Aggregations