/** Returns all addresses (any scope) for interfaces that are up. * This is only used to pick a publish address, when the user set network.host to a wildcard */ static InetAddress[] getAllAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all interface-local scope (loopback) addresses for interfaces that are up. */ static InetAddress[] getLoopbackAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running loopback addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all global scope addresses for interfaces that are up. */ static InetAddress[] getGlobalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress() == false && address.isSiteLocalAddress() == false && address.isLinkLocalAddress() == false) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running global-scope (public) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
for (NetworkInterface nic : NetworkUtils.getInterfaces()) { msg.append(System.lineSeparator());
/** Returns all addresses (any scope) for interfaces that are up. * This is only used to pick a publish address, when the user set network.host to a wildcard */ static InetAddress[] getAllAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all addresses (any scope) for interfaces that are up. * This is only used to pick a publish address, when the user set network.host to a wildcard */ static InetAddress[] getAllAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all interface-local scope (loopback) addresses for interfaces that are up. */ static InetAddress[] getLoopbackAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running loopback addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all addresses (any scope) for interfaces that are up. * This is only used to pick a publish address, when the user set network.host to a wildcard */ static InetAddress[] getAllAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all addresses (any scope) for interfaces that are up. * This is only used to pick a publish address, when the user set network.host to a wildcard */ static InetAddress[] getAllAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { list.add(address); } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { Optional<NetworkInterface> networkInterface = getInterfaces().stream().filter((netIf) -> name.equals(netIf.getName())).findFirst(); if (networkInterface.isPresent() == false) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!networkInterface.get().isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(networkInterface.get().getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all site-local scope (private) addresses for interfaces that are up. */ static InetAddress[] getSiteLocalAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isSiteLocalAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns all interface-local scope (loopback) addresses for interfaces that are up. */ static InetAddress[] getLoopbackAddresses() throws SocketException { List<InetAddress> list = new ArrayList<>(); for (NetworkInterface intf : getInterfaces()) { if (intf.isUp()) { for (InetAddress address : Collections.list(intf.getInetAddresses())) { if (address.isLoopbackAddress()) { list.add(address); } } } } if (list.isEmpty()) { throw new IllegalArgumentException("No up-and-running loopback addresses found, got " + getInterfaces()); } return list.toArray(new InetAddress[list.size()]); }
/** Returns addresses for the given interface (it must be marked up) */ static InetAddress[] getAddressesForInterface(String name) throws SocketException { NetworkInterface intf = NetworkInterface.getByName(name); if (intf == null) { throw new IllegalArgumentException("No interface named '" + name + "' found, got " + getInterfaces()); } if (!intf.isUp()) { throw new IllegalArgumentException("Interface '" + name + "' is not up and running"); } List<InetAddress> list = Collections.list(intf.getInetAddresses()); if (list.isEmpty()) { throw new IllegalArgumentException("Interface '" + name + "' has no internet addresses"); } return list.toArray(new InetAddress[list.size()]); }