MCPcopy Create free account
hub / github.com/diyhi/bbs / getClientIpAddress

Method getClientIpAddress

src/main/java/cms/utils/IpAddress.java:58–78  ·  view source on GitHub ↗

获取IP地址 @param request 请求信息 @return

(HttpServletRequest request)

Source from the content-addressed store, hash-verified

56 * @return
57 */
58 public static String getClientIpAddress(HttpServletRequest request){
59 String ip=request.getHeader("X-Forwarded-For");
60 if(ip==null || ip.isEmpty() ||"unknown".equalsIgnoreCase(ip)){
61 ip=request.getHeader("Proxy-Client-IP");
62 }
63 if(ip==null || ip.isEmpty() ||"unknown".equalsIgnoreCase(ip)){
64 ip=request.getHeader("WL-Proxy-Client-IP");
65 }
66 if(ip==null || ip.isEmpty() ||"unknown".equalsIgnoreCase(ip)){
67 ip=request.getRemoteAddr();
68 }
69 //对于通过多个代理的情况, 第一个IP为客户端真实IP,多个IP按照','分割 "***.***.***.***".length()
70 if (ip != null && ip.length() > 15) { // "***.***.***.***".length()
71 // = 15
72 if (ip.indexOf(",") > 0) {
73 ip = ip.substring(0, ip.indexOf(","));
74 }
75 }
76
77 return ip;
78 }
79
80 /**
81 private static final String[] HEADERS_TO_TRY = {

Callers 15

addFeedbackMethod · 0.95
addMethod · 0.95
loginMethod · 0.95
tokenRenewalMethod · 0.95
addPVMethod · 0.95
getQuestionDetailMethod · 0.95
addQuestionMethod · 0.95
getTopicDetailMethod · 0.95
addTopicMethod · 0.95
getAnswerPageMethod · 0.95
addAnswerMethod · 0.95
addAnswerReplyMethod · 0.95

Calls 1

isEmptyMethod · 0.45

Tested by

no test coverage detected