当前位置: 代码迷 >> Web前端 >> java 获取ip的工具种
  详细解决方案

java 获取ip的工具种

热度:249   发布时间:2013-08-04 18:26:16.0
java 获取ip的工具类
public class GetIpUtil {
	
	/*
	 * 获取用户的IP
	 */
	public static String getUserIP(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.getRemoteAddr();
		}
		return ip;
	}

?

  相关解决方案