java 后台获取访问客户端ip地址

来源:互联网 发布:c语言指针例子 编辑:程序博客网 时间:2024/04/30 05:24
protected String getClientIpAddress(HttpServletRequest request) {String clientIp = request.getHeader("x-forwarded-for");if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {clientIp = request.getHeader("Proxy-Client-IP");}if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {clientIp = request.getHeader("WL-Proxy-Client-IP");}if(clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {clientIp = request.getRemoteAddr();}return clientIp;}

1 0