前台获取信息
2016-02-26 12:25
246 查看
![这样的](https://img-blog.csdn.net/20160226111027254)
javascript代码 function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows"); var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel"); if (isMac) return "Mac"; var isUnix = (navigator.platform == "X11") && !isWin && !isMac; if (isUnix) return "Unix"; var isLinux = (String(navigator.platform).indexOf("Linux") > -1); if (isLinux) return "Linux"; if (isWin) { var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1; if (isWin2K) return "Windows 2000"; var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1; if (isWinXP) return "Windows XP"; var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1; if (isWin2003) return "Windows 2003"; var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1; if (isWinVista) return "Windows Vista"; var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1; if (isWin7) return "Windows 7"; } return "other"; } function userAgent(){ var ua = navigator.userAgent; ua = ua.toLowerCase(); var match = /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || []; //如果需要获取浏览器版本号:match[2] switch(match[1]){ case "msie": //ie return "Internet Explorer "+parseInt(match[2]); break; case "webkit": //safari or chrome return "safari or chrome"+parseInt(match[2]); break; case "opera": //opera return "opera"+parseInt(match[2]); break; case "mozilla": //Firefox return "mozilla Firefox"+parseInt(match[2]); break; default: break; } } function openWords(conId){ window.location.href="${pageContext.request.contextPath}/content/edit.htm?contentId="+conId; }
后台获取ip代码 /** * 获取访问者IP * 在一般情况下使用Request.getRemoteAddr()即可,但是经过nginx等反向代理软件后,这个方法会失效。 * 本方法先从Header中获取X-Real-IP,如果不存在再从X-Forwarded-For获得第一个IP(用,分割), * 如果还不存在则调用Request .getRemoteAddr()。 * * @param request * @return */ protected String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-Real-IP"); if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) { return ip; } ip = request.getHeader("X-Forwarded-For"); if (!StringUtils.isBlank(ip) && !"unknown".equalsIgnoreCase(ip)) { // 多次反向代理后会有多个IP值,第一个为真实IP。 int index = ip.indexOf(','); if (index != -1) { return ip.substring(0, index); } else { return ip; } } else { return request.getRemoteAddr(); } }
内存获取 public class OsInfo { public String getTotalMemory() { DecimalFormat dcmFmt = new DecimalFormat("0.0"); OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long totalvirtualMemory = osmxb.getTotalSwapSpaceSize(); totalvirtualMemory = osmxb.getTotalPhysicalMemorySize(); float totals = (float) totalvirtualMemory / (1024 * 1024); return dcmFmt.format(totals); } public String getFreeMemory() { DecimalFormat dcmFmt = new DecimalFormat("0.0"); OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize(); float frees = (float) freePhysicalMemorySize / (1024 * 1024); return dcmFmt.format(frees); } public String getUsedMemory() { DecimalFormat dcmFmt = new DecimalFormat("0.0"); OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long totalvirtualMemory = osmxb.getTotalSwapSpaceSize(); totalvirtualMemory = osmxb.getTotalPhysicalMemorySize(); float totals = (float) totalvirtualMemory / (1024 * 1024); long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize(); float frees = (float) freePhysicalMemorySize / (1024 * 1024); float compare = (float) (totals - frees); return dcmFmt.format(compare); } }
HashMap<String, String> osInfo = new HashMap<String, String>(); osInfo.put("osName", (String) System.getProperty("os.name")); osInfo.put("osArch", System.getProperty("os.arch")); osInfo.put("osVersion", System.getProperty("os.version")); osInfo.put("jvmName", System.getProperty("java.vm.name")); osInfo.put("jvmVersion", System.getProperty("java.vm.version")); osInfo.put("javaVersion", System.getProperty("java.version")); osInfo.put("serverInfo", context.getServerInfo());
相关文章推荐
- Switch between Server Core mode and Server GUI mode in Windows Server 2012 R2
- bzoj 1003: [ZJOI2006]物流运输trans 最短路+dp
- Sublime Text3安装emmet插件
- iOS UIAlertController弹框(OS9.0 后替代UIAlertView弹框和UIActionSheet下弹框)
- Android:自定义View(随机生成验证码)
- peration not supported. Unknown error: 0x8973190e
- Linux内核分析——计算机是如何工作的
- Java 位运算和运算符总结
- sgdisk用法
- 安全相关文章记录
- Centos6.6上安装mysql5.6中的一些典型问题
- C/C++学习建议(摘抄自:程序员2010年8月P61页)
- 嵌入式MCU开发群资源
- google maps js v3 api教程(2) -- 在地图上添加标记
- Eclipse解决bug:JDK是8.0,打不开eclipse
- Redis集群添加节点
- WinCE 用代码创建连接"PPPOE”
- partprobe命令用法
- OC基础笔记
- 【数位DP】BZOJ3780数字统计