java获取访问系统的ip,操作系统,浏览器信息

1,获取ip地址

String ip = req.getHeader("x-forwarded-for"); 
        if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)){
            ip = req.getHeader("Proxy-Client-IP");
        }
        if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)){
            ip = req.getHeader("WL-Proxy-Client-IP");
        }
        if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)){
            ip = req.getRemoteAddr();
        }
        if(ip.equals("0:0:0:0:0:0:0:1")){
            ip="127.0.0.1";
        }

2,获取操作系统

String operation = System.getProperty("os.name"); 

3,获取浏览器信息

String browser = req.getHeader("User-Agent");

你可能感兴趣的:(java)