IpUtils { public static String getIp(SocketAddress socketAddress){ if(socketAddress instanceof InetSocketAddress){ InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; String ip = inetSocketAddress.getAddress().getHostAddress(); return ip; } throw new IllegalStateException("unknown socketaddress type:" + socketAddress.getClass() + "," + socketAddress); }  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 testGetIp(){ InetSocketAddress address = new InetSocketAddress("localhost", 6379); logger.info("{}", IpUtils.getIp(address)); logger.info("{}", address.getAddress().getHostAddress()); }