MCPcopy Create free account
hub / github.com/Hello-hao/Tbed / getIpAddr

Method getIpAddr

src/main/java/cn/hellohao/utils/GetIPS.java:28–45  ·  view source on GitHub ↗
(HttpServletRequest request)

Source from the content-addressed store, hash-verified

26 }
27
28 public static String getIpAddr(HttpServletRequest request){
29 String ip = request.getHeader("X-Forwarded-For");
30 if(org.apache.commons.lang3.StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
31 //多次反向代理后会有多个ip值,第一个ip才是真实ip
32 int index = ip.indexOf(",");
33 if(index != -1){
34 return ip.substring(0,index);
35 }else{
36 return ip;
37 }
38 }
39 ip = request.getHeader("X-Real-IP");
40 if(org.apache.commons.lang3.StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
41 return ip;
42 }
43 return request.getRemoteAddr();
44
45 }
46
47
48}

Callers 3

WelcomeMethod · 0.95
uploadForLocMethod · 0.95
uploadImgMethod · 0.95

Calls 1

getHeaderMethod · 0.80

Tested by

no test coverage detected