public static String getIp()

in common/src/main/java/org/apache/rocketmq/schema/registry/common/utils/CommonUtil.java [254:284]


    public static String getIp() {
        String ip = "";

        try {
            Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
            InetAddress inetAddress;
            boolean found = false;
            while (netInterfaces.hasMoreElements() && !found) {
                NetworkInterface ni = netInterfaces.nextElement();
                Enumeration<InetAddress> address = ni.getInetAddresses();
                while (address.hasMoreElements()) {
                    inetAddress = address.nextElement();
                    if (!inetAddress.isSiteLocalAddress()
                        && !inetAddress.isLoopbackAddress()
                        && !inetAddress.getHostAddress().contains(":")) {
                        ip = inetAddress.getHostAddress();
                        found = true;
                        break;
                    } else if (inetAddress.isSiteLocalAddress()
                        && !inetAddress.isLoopbackAddress()
                        && !inetAddress.getHostAddress().contains(":")) {
                        ip = inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException e) {
            throw new SchemaException("Get IP failed", e);
        }

        return ip;
    }