欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

从request获取远程IP地址

程序员文章站 2022-07-10 17:39:43
...
	  public static String getIpAddr(HttpServletRequest request) {
		  String ip = request.getHeader("X-Forwarded-For");
		  if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			  ip = request.getHeader("Proxy-Client-IP");
		  }
		  if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			  ip = request.getHeader("WL-Proxy-Client-IP");
		  }
		  if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			  ip = request.getHeader("HTTP_CLIENT_IP");
		  }
		  if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			  ip = request.getHeader("HTTP_X_FORWARDED_FOR");
		  }
		  if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			  ip = request.getRemoteAddr();
		  }
		  	return ip;
	  }

  这个不能获取本地启动的项目的IP

posted on 2016-12-29 14:00 Gavin_Yi 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/gavin2016/p/IP.html