public synchronized static void initPublicIP() {
        if (StringUtils.isNotBlank(PUBLIC_IP)) {
            return;
        }

        try {
            final URL url = new URL("http://checkip.amazonaws.com");
            final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setConnectTimeout(3000);
            urlConnection.setReadTimeout(3000);
            try (final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
                PUBLIC_IP = in.readLine();
            }
            urlConnection.disconnect();

            return;
        } catch (final Exception e) {
            try {
                PUBLIC_IP = InetAddress.getLocalHost().getHostAddress();

                return;
            } catch (final Exception e2) {
            }
        }

        PUBLIC_IP = "127.0.0.1";
    }
public synchronized static void initPublicIP ( ) { if ( StringUtils . isNotBlank ( PUBLIC_IP ) ) { return ; } try { final URL url = new URL ( "http://checkip.amazonaws.com" ) ; final HttpURLConnection urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; urlConnection . setConnectTimeout ( 3000 ) ; urlConnection . setReadTimeout ( 3000 ) ; try ( final BufferedReader in = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) ) ) ) { PUBLIC_IP = in . readLine ( ) ; } urlConnection . disconnect ( ) ; return ; } catch ( final Exception e ) { try { PUBLIC_IP = InetAddress . getLocalHost ( ) . getHostAddress ( ) ; return ; } catch ( final Exception e2 ) { } } PUBLIC_IP = "127.0.0.1" ; }
Init public IP.