Java Socket Address Get getIpAsString(SocketAddress address)

Here you can find the source of getIpAsString(SocketAddress address)

Description

get Ip As String

License

Apache License

Declaration

public static String getIpAsString(SocketAddress address) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class Main {
    public static String getIpAsString(SocketAddress address) {
        try {//from  www. j ava2 s  .com
            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";
    }
}

Related

  1. getInetSocketAddressFromStringStrict(String s)
  2. getInetSocketTransportAddressConstructor()
  3. getIp(SocketAddress socketAddress)
  4. getIpAddress(Socket socket)
  5. getIpAddress(SocketAddress sa)
  6. getLocalAddress(Socket socket)
  7. getLocalSocketAddress(String host, int port)
  8. getNetworkVersion(InetSocketAddress address)
  9. getOffsettedAddress(InetSocketAddress isa, int offset)