首页 > 代码库 > 获取客户端IP

获取客户端IP

/***
     * 获取客户端IP
     * @param request
     * @return
     */
    public static String getIpAddrByRequest(HttpServletRequest request) {
        String ip=null;
        if(request.getHeader("x-real-ip") == null)
        {
        ip = request.getRemoteAddr();
        }
        else
        {
        ip = request.getHeader("x-real-ip");
        }
        return ip;
    }