IpUtils { public static boolean isValidIpFormat(String ip) { return ip != null && com.google.common.net.InetAddresses.isInetAddress(ip); }  static String getIp(SocketAddress socketAddress); static boolean isValidIpFormat(String ip); static boolean isPort(String str); static InetAddress getFistNonLocalIpv4ServerAddress(); static InetAddress getFistNonLocalIpv4ServerAddress(String ipPrefixPrefer); static boolean isLocal(String host); static List<HostPort> parseAsHostPorts(String addressDesc); static List<InetSocketAddress> parse(String addressDesc); static InetSocketAddress parseSingle(String singleAddress); static Pair<String, Integer> parseSingleAsPair(String singleAddress); static String[] splitIpAddr(String ip);  }
@Test public void testIsValidIp() { String ipv4 = "192.168.0.1"; Assert.assertTrue(IpUtils.isValidIpFormat(ipv4)); String ipv6 = "fe80::1ff:fe23:4567:890a"; Assert.assertTrue(IpUtils.isValidIpFormat(ipv6)); ipv6 = "fe80::1ff:fe23:4567:890a"; Assert.assertTrue(IpUtils.isValidIpFormat(ipv6)); }