/**
* 获取浏览器的ip地址
* @param request
* @return
*/
public static String getIP(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (!checkIP(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (!checkIP(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (!checkIP(ip)) {
ip = request.getRemoteAddr();
}
if("0:0:0:0:0:0:0:1".equals(ip)){
ip = "127.0.0.1";
}
return ip;
}
private static boolean checkIP(String ip) {
if (ip == null || ip.length() == 0 || "unkown".equalsIgnoreCase(ip)
|| ip.split("\.").length != 4) {
return false;
}
return true;
}
/**
* 获取浏览器类型
* @param request
* @return
*/
public static String getUserAgent(HttpServletRequest request) {
String agent = request.getHeader("User-Agent");
return agent;
}