编程语言
首页 > 编程语言> > java获取当前网络IP地址

java获取当前网络IP地址

作者:互联网

 

 

 1  /**
 2      * 获取当前网络ip
 3      *
 4      * @param request
 5      * @return
 6      */
 7     @RequestMapping("getIpAddress")
 8     public static String getIpAddress(HttpServletRequest request) {
 9         String ip = request.getHeader("x-forwarded-for");
10         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
11             ip = request.getHeader("Proxy-Client-IP");
12         }
13         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
14             ip = request.getHeader("WL-Proxy-Client-IP");
15         }
16         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
17             ip = request.getHeader("HTTP_CLIENT_IP");
18         }
19         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
20             ip = request.getHeader("HTTP_X_FORWARDED_FOR");
21         }
22         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
23             ip = request.getRemoteAddr();
24         }
25         return ip;
26     }

 

标签:java,equalsIgnoreCase,ip,getHeader,request,unknown,获取,IP地址,null
来源: https://www.cnblogs.com/lwl80/p/15778157.html