public static String getIp() {
        if (null != cachedIpAddress) {
            return cachedIpAddress;
        }
        Enumeration<NetworkInterface> netInterfaces;
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (final SocketException ex) {
            throw new EagleFrameException(ex);
        }
        String localIpAddress = null;
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface netInterface = netInterfaces.nextElement();
            Enumeration<InetAddress> ipAddresses = netInterface.getInetAddresses();
            while (ipAddresses.hasMoreElements()) {
                InetAddress ipAddress = ipAddresses.nextElement();
                if (isPublicIpAddress(ipAddress)) {
                    String publicIpAddress = ipAddress.getHostAddress();
                    cachedIpAddress = publicIpAddress;
                    return publicIpAddress;
                }
                if (isLocalIpAddress(ipAddress)) {
                    localIpAddress = ipAddress.getHostAddress();
                }
            }
        }
        cachedIpAddress = localIpAddress;
        return localIpAddress;
    }
public static String getIp() {
        if (null != cachedIpAddress) {
            return cachedIpAddress;
        }
        Enumeration<NetworkInterface> netInterfaces;
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (final SocketException ex) {
            throw new EagleFrameException(ex);
        }
        String localIpAddress = null;
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface netInterface = netInterfaces.nextElement();
            Enumeration<InetAddress> ipAddresses = netInterface.getInetAddresses();
            while (ipAddresses.hasMoreElements()) {
                InetAddress ipAddress = ipAddresses.nextElement();
                if (isPublicIpAddress(ipAddress)) {
                    String publicIpAddress = ipAddress.getHostAddress();
                    cachedIpAddress = publicIpAddress;
                    return publicIpAddress;
                }
                if (isLocalIpAddress(ipAddress)) {
                    localIpAddress = ipAddress.getHostAddress();
                }
            }
        }
        cachedIpAddress = localIpAddress;
        return localIpAddress;
    }
public static String getIp ( ) { if ( null != cachedIpAddress ) { return cachedIpAddress ; } Enumeration < NetworkInterface > netInterfaces ; try { netInterfaces = NetworkInterface . getNetworkInterfaces ( ) ; } catch ( final SocketException ex ) { throw new EagleFrameException ( ex ) ; } String localIpAddress = null ; while ( netInterfaces . hasMoreElements ( ) ) { NetworkInterface netInterface = netInterfaces . nextElement ( ) ; Enumeration < InetAddress > ipAddresses = netInterface . getInetAddresses ( ) ; while ( ipAddresses . hasMoreElements ( ) ) { InetAddress ipAddress = ipAddresses . nextElement ( ) ; if ( isPublicIpAddress ( ipAddress ) ) { String publicIpAddress = ipAddress . getHostAddress ( ) ; cachedIpAddress = publicIpAddress ; return publicIpAddress ; } if ( isLocalIpAddress ( ipAddress ) ) { localIpAddress = ipAddress . getHostAddress ( ) ; } } } cachedIpAddress = localIpAddress ; return localIpAddress ; }
获取本机IP地址.

<p>
有限获取外网IP地址.
也有可能是链接着路由器的最终IP地址.
</p>

@return 本机IP地址
获取本机IP地址 .