NetUtils { public static boolean isInvalidLocalHost(String host) { return host == null || host.length() == 0 || host.equalsIgnoreCase(LOCALHOST_KEY) || host.equals(ANYHOST_VALUE) || host.startsWith("127."); }  static int getRandomPort(); static int getAvailablePort(); static int getAvailablePort(int port); static boolean isInvalidPort(int port); static boolean isValidAddress(String address); static boolean isLocalHost(String host); static boolean isAnyHost(String host); static boolean isInvalidLocalHost(String host); static boolean isValidLocalHost(String host); static InetSocketAddress getLocalSocketAddress(String host, int port); static String getLocalHost(); static String filterLocalHost(String host); static String getIpByConfig(); static InetAddress getLocalAddress(); static boolean isPreferredNetworkInterface(NetworkInterface networkInterface); static NetworkInterface findNetworkInterface(); static String getHostName(String address); static String getIpByHost(String hostName); static String toAddressString(InetSocketAddress address); static InetSocketAddress toAddress(String address); static String toURL(String protocol, String host, int port, String path); static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress); static void setInterface(MulticastSocket multicastSocket, boolean preferIpv6); static boolean matchIpExpression(String pattern, String host, int port); static boolean matchIpRange(String pattern, String host, int port); static boolean isMulticastAddress(String host);  }
@Test public void testIsInvalidLocalHost() throws Exception { assertTrue(NetUtils.isInvalidLocalHost(null)); assertTrue(NetUtils.isInvalidLocalHost("")); assertTrue(NetUtils.isInvalidLocalHost("localhost")); assertTrue(NetUtils.isInvalidLocalHost("0.0.0.0")); assertTrue(NetUtils.isInvalidLocalHost("127.1.2.3")); assertTrue(NetUtils.isInvalidLocalHost("127.0.0.1")); assertFalse(NetUtils.isInvalidLocalHost("128.0.0.1")); }