获取ip

public static String getClientIp() {
        HttpServletRequest request = HttpKit.getRequest();
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null) {
            ip = request.getRemoteAddr();
        }

        String[] ipArrays = ip.split(",");
        return ipArrays.length > 0 ? ipArrays[0] : ip;
    }

 

posted @ 2023-04-18 09:53  二次元的程序猿  阅读(16)  评论(0编辑  收藏  举报