NetworkUtils { public static List<String> getIPs() { final List<String> ips = new ArrayList<>(); final String ipAddressRegex = "[1-9][0-9]{0,2}\\.[0-9]{0,3}\\.[0-9]{0,3}\\.[0-9]{0,3}"; final Pattern ipAddressPattern = Pattern.compile(ipAddressRegex); final Enumeration<NetworkInterface> interfaces; Matcher ipAddressMatcherMatcher; try { interfaces = NetworkInterface.getNetworkInterfaces(); Enumeration<InetAddress> inetAddresses; InetAddress inet; while (interfaces.hasMoreElements()) { inetAddresses = interfaces.nextElement().getInetAddresses(); while (inetAddresses.hasMoreElements()) { inet = inetAddresses.nextElement(); ipAddressMatcherMatcher = ipAddressPattern.matcher(inet.getHostAddress()); if (ipAddressMatcherMatcher.matches()) ips.add(inet.getHostAddress()); } } Collections.sort(ips); } catch (SocketException e) { LOGGER.finest("Can not find network interfaces"); } return ips; }  static String getIP(); static List<String> getIPs(); static ObservableList<String> getObservableIps();  }
@Test public void testGetIps() { final List<String> ips = NetworkUtils.getIPs(); assertNotNull(ips); assertTrue(ips.size() > 0); assertTrue(ips.contains("127.0.0.1")); }