IpUtils { public static boolean isLocal(String host){ if(host.startsWith("/")){ host = host.substring(1); } for(InetAddress address : getAllServerAddress()){ logger.debug("{}", address.getHostAddress()); if(host.equalsIgnoreCase(getAddressString(getAddressString(address.getHostAddress())))){ return true; } } return false; }  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 testIsLocal(){ logger.info("{}", IpUtils.isLocal("127.0.0.1")); logger.info("{}", IpUtils.isLocal("10.32.21.2")); logger.info("{}", IpUtils.isLocal("10.32.21.3")); logger.info("{}", IpUtils.isLocal("0:0:0:0:0:0:0:1")); }