JAVA 获取当前机器的IP

public static String getIp(){
        try {
            if(ip==null||ip.isEmpty()){
                ip =InetAddress.getLocalHost().getHostAddress();
            }
            return ip;
        } catch (UnknownHostException e) {
            throw new AtomException(BusinessPrompt.GET_IP_FAIL_CODE, BusinessPrompt.GET_IP_FAIL_MSG, FrameworkConstants.ATOM_LVL);
        }
    }

你可能感兴趣的:(JAVA)