List of utility methods to do Socket Address Get
InetSocketAddress | getInetSocketAddressFromStringStrict(String s) get Inet Socket Address From String Strict String[] tokens = s.split(":"); if (tokens.length < 2) { return null; return new InetSocketAddress(tokens[0], Integer.valueOf(tokens[1])); |
Constructor> | getInetSocketTransportAddressConstructor() get Inet Socket Transport Address Constructor try { Class<?> clazz = Class.forName("org.elasticsearch.common.transport.InetSocketTransportAddress"); return clazz.getConstructor(InetSocketAddress.class); } catch (ClassNotFoundException e) { return null; } catch (NoSuchMethodException e) { return null; } catch (SecurityException e) { ... |
String | getIp(SocketAddress socketAddress) get Ip if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; String ip = inetSocketAddress.getAddress().toString(); if (ip.charAt(0) == '/') { return ip.substring(1); return ip; throw new IllegalStateException( "unknown socketaddress type:" + socketAddress.getClass() + "," + socketAddress); |
String | getIpAddress(Socket socket) get Ip Address return socket.getInetAddress().toString().substring(1);
|
String | getIpAddress(SocketAddress sa) get Ip Address String ip = sa.toString(); if (ip == null) return ""; if (ip.startsWith("/")) ip = ip.substring(1); int i = ip.indexOf(":"); if (i > 0) ip = ip.substring(0, i); ... |
String | getIpAsString(SocketAddress address) get Ip As String try { if (address instanceof InetSocketAddress) { return ((InetSocketAddress) address).getAddress().getHostAddress(); return address.toString().split("/")[1].split(":")[0]; } catch (Throwable e) { e.printStackTrace(); return "0.0.0.0"; |
String | getLocalAddress(Socket socket) get Local Address String localAddress = socket == null || socket.getLocalAddress() == null ? "" : socket.getLocalAddress().toString() + ":" + socket.getLocalPort(); if (localAddress.startsWith("/")) { localAddress = localAddress.substring(1); return localAddress; |
InetSocketAddress | getLocalSocketAddress(String host, int port) get Local Socket Address return isInvalidLocalHost(host) ? new InetSocketAddress(port) : new InetSocketAddress(host, port); |
int | getNetworkVersion(InetSocketAddress address) get Network Version if (address == null) { throw new IllegalArgumentException("Address cannot be null"); if (address.getAddress() instanceof Inet4Address) { return 4; } else if (address.getAddress() instanceof Inet6Address) { return 6; throw new UnsupportedOperationException("Unknown network version " + address.getClass().getSimpleName()); |
InetSocketAddress | getOffsettedAddress(InetSocketAddress isa, int offset) get Offsetted Address return offset == 0 ? isa : new InetSocketAddress(isa.getAddress(), isa.getPort() + offset); |