1. 检测jdk版本

 @SuppressWarnings("LoopStatementThatDoesntLoop")private static int javaVersion0() {int javaVersion;// Not really a loopfor (;;) {// Androidif (isAndroid()) {javaVersion = 6;break;}try {Class.forName("java.time.Clock", false, getClassLoader(Object.class));javaVersion = 8;break;} catch (Exception e) {// Ignore
            }try {Class.forName("java.util.concurrent.LinkedTransferQueue", false, getClassLoader(BlockingQueue.class));javaVersion = 7;break;} catch (Exception e) {// Ignore
            }javaVersion = 6;break;}if (logger.isDebugEnabled()) {logger.debug("Java version: {}", javaVersion);}return javaVersion;}

2. 检测是否window

    private static boolean isWindows0() {boolean windows = SystemPropertyUtil.get("os.name", "").toLowerCase(Locale.US).contains("win");if (windows) {logger.debug("Platform: Windows");}return windows;}

3. 检测是否root权限

private static boolean isRoot0() {if (isWindows()) {return false;}String[] ID_COMMANDS = { "/usr/bin/id", "/bin/id", "/usr/xpg4/bin/id", "id"};Pattern UID_PATTERN = Pattern.compile("^(?:0|[1-9][0-9]*)$");for (String idCmd: ID_COMMANDS) {Process p = null;BufferedReader in = null;String uid = null;try {p = Runtime.getRuntime().exec(new String[] { idCmd, "-u" });in = new BufferedReader(new InputStreamReader(p.getInputStream(), CharsetUtil.US_ASCII));uid = in.readLine();in.close();for (;;) {try {int exitCode = p.waitFor();if (exitCode != 0) {uid = null;}break;} catch (InterruptedException e) {// Ignore
                    }}} catch (Exception e) {// Failed to run the command.uid = null;} finally {if (in != null) {try {in.close();} catch (IOException e) {// Ignore
                    }}if (p != null) {try {p.destroy();} catch (Exception e) {// Android sometimes triggers an ErrnoException.
                    }}}if (uid != null && UID_PATTERN.matcher(uid).matches()) {logger.debug("UID: {}", uid);return "0".equals(uid);}}logger.debug("Could not determine the current UID using /usr/bin/id; attempting to bind at privileged ports.");Pattern PERMISSION_DENIED = Pattern.compile(".*(?:denied|not.*permitted).*");for (int i = 1023; i > 0; i --) {ServerSocket ss = null;try {ss = new ServerSocket();ss.setReuseAddress(true);ss.bind(new InetSocketAddress(i));if (logger.isDebugEnabled()) {logger.debug("UID: 0 (succeded to bind at port {})", i);}return true;} catch (Exception e) {// Failed to bind.// Check the error message so that we don't always need to bind 1023 times.String message = e.getMessage();if (message == null) {message = "";}message = message.toLowerCase();if (PERMISSION_DENIED.matcher(message).matches()) {break;}} finally {if (ss != null) {try {ss.close();} catch (Exception e) {// Ignore.
                    }}}}logger.debug("UID: non-root (failed to bind at any privileged ports)");return false;}

4.检测最大直接内存

private static long maxDirectMemory0() {long maxDirectMemory = 0;try {// Try to get from sun.misc.VM.maxDirectMemory() which should be most accurate.Class<?> vmClass = Class.forName("sun.misc.VM", true, getSystemClassLoader());Method m = vmClass.getDeclaredMethod("maxDirectMemory");maxDirectMemory = ((Number) m.invoke(null)).longValue();} catch (Throwable t) {// Ignore
        }if (maxDirectMemory > 0) {return maxDirectMemory;}try {// Now try to get the JVM option (-XX:MaxDirectMemorySize) and parse it.// Note that we are using reflection because Android doesn't have these classes.Class<?> mgmtFactoryClass = Class.forName("java.lang.management.ManagementFactory", true, getSystemClassLoader());Class<?> runtimeClass = Class.forName("java.lang.management.RuntimeMXBean", true, getSystemClassLoader());Object runtime = mgmtFactoryClass.getDeclaredMethod("getRuntimeMXBean").invoke(null);@SuppressWarnings("unchecked")List<String> vmArgs = (List<String>) runtimeClass.getDeclaredMethod("getInputArguments").invoke(runtime);for (int i = vmArgs.size() - 1; i >= 0; i --) {Matcher m = MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN.matcher(vmArgs.get(i));if (!m.matches()) {continue;}maxDirectMemory = Long.parseLong(m.group(1));switch (m.group(2).charAt(0)) {case 'k': case 'K':maxDirectMemory *= 1024;break;case 'm': case 'M':maxDirectMemory *= 1024 * 1024;break;case 'g': case 'G':maxDirectMemory *= 1024 * 1024 * 1024;break;}break;}} catch (Throwable t) {// Ignore
        }if (maxDirectMemory <= 0) {maxDirectMemory = Runtime.getRuntime().maxMemory();logger.debug("maxDirectMemory: {} bytes (maybe)", maxDirectMemory);} else {logger.debug("maxDirectMemory: {} bytes", maxDirectMemory);}return maxDirectMemory;}

等等

转载于:https://www.cnblogs.com/davidwang456/p/5121956.html

netty检测系统工具PlatformDependent相关推荐

  1. 实验五:系统检测维护工具Wsycheck使用

    目录 一.实验目的及要求 二.实验原理 三.实验环境 四.实验步骤及内容 4.1:了解程序主界面 4.1.1看看Wsyscheck的标题栏,标题栏看似没什么异样,仔细观察就会发现它的特点:随机文件名. ...

  2. Wsyscheck(系统检测维护工具) v1.68.33绿色版

    软件名称:系统检测维护工具(Wsyscheck) v1.68.33绿色版 软件类别:国产软件 运行环境:windows 软件语言:简体中文 授权方式:免费版 软件大小:1022 KB 软件等级: 整理 ...

  3. ibm db2获取目标时间与当前时间的差值_高帧频视觉实时目标检测系统

    基于机器视觉的智能目标检测系统应用非常广泛,尤其在航天军工等领域中,经常涉及高速目标的实时检测和控制,对目标检测的智能性和实时性提出了更严格的要求.在这种应用中,视觉系统相对雷达.声纳具有信息量大.抗 ...

  4. 网络入侵检测规避工具fragrouter

    网络入侵检测规避工具fragrouter 网络入侵检测系统可以通过拦截数据包,获取内容进而判断是否为恶意数据包.对于传输较大的数据包,通常会采用分片的方式,将大数据包拆分为小数据包进行传输.如果入侵检 ...

  5. 两款自动检测代码工具与插件,开源真香

    大家好,我是TJ 一个励志推荐10000款开源项目与工具的程序员 写完代码最麻烦的是什么?就是运行时出现bug再回头去改去修,如果有一款检测工具,能自动检测出代码中是否存在bug是不是对开发者来说,更 ...

  6. 测试两个主机之间的连通性_UCloud 全链路大规模网络连通性检测系统详解

    虚拟网络排查问题困难,传统的 traceroute 等工具很难起到太大作用,大部分情况下都需要到宿主机.混合云网关上抓包来 troubleshooting,耗时又费力.有些场景中包的传送路径比较长(如 ...

  7. Linux -- ***检测系统(IDS)介绍及应用(1)

    一.***检测工具简介 Internet上的服务器一般都会被安置在防火墙的DMZ(Demilitarized Zone)区,受到防火墙的保护.这在一定程度可以防止具有已知非法特征的危险连接和恶意*** ...

  8. 【WEB安全】In0ri:基于深度学习的网站内容污染检测系统

    关于In0ri In0ri是一个内容污染检测系统,该工具主要利用一个图像分类卷积神经网络实现其功能. 在监控网站时,In0ri会定期抓取网站的屏幕截图,然后将其放入预处理器,预处理器将图像大小调整为2 ...

  9. 拉索检测机器人_昌都斜拉索锈蚀检测系统,斜拉索检测机器人推荐

    ()考虑到斜拉索的耐久性,在后续的斜拉桥设计中应着重研判和创新的内容包括:拉索自身可检修.易更换设计,例如钢绞线拉索防护体系,对于索体,单根钢绞线包裹环氧涂层,整束钢绞线外包防护,钢绞线与防护层之间灌 ...

最新文章

  1. 7-1 作业调度算法--先来先服务 (30 分)(思路+详解+vector+map+map做法)Come Baby!!!!!!!!!!!
  2. [转载]基于TFS实践敏捷-修复Bug和执行代码评审
  3. vue.js源码学习分享(五)
  4. vue webpack打包入口文件是哪个_Vue 学习笔记(二十五):webpack 相关
  5. 在字符串String类型常忘记使用equals()进行值比较的问题
  6. 从零开始编写深度学习库(五)PoolingLayer 网络层CPU编写
  7. vi/vim: 文件浏览和缓冲区浏览
  8. 人脸检测(十)--强分类器源码分析
  9. 教你摆脱低级程序猿 项目中cocopads的安装使用
  10. linux etcfstab文件,Linux中/etc/fstab文件详解
  11. mac虚拟机服务器设置u盘启动不了,mac虚拟机如何使用u盘启动盘
  12. 向Docker告别的时候到了
  13. 现在大多数论文存在的弊病——可重复性
  14. 使用uiautomatorviewer报错Error obtaining UI hierarchy
  15. PDMS二次开发(十四)——自动插入焊口和计算焊接当量(达因数)
  16. 浏览器 Web 访问剪切板图片
  17. 数据链路层的有那三个基本问题?为什么都必须加以解决?
  18. 如何设置搭建内网共享服务器?并实现外网访问?
  19. 【ISP】CMOS(3)-sensor特性
  20. python算法工程师需要学什么_成为一名 AI 算法工程师,你需要具备哪些能力?...

热门文章

  1. dbartisan mysql_Sybase数据库安全
  2. linux etc 漏洞利用,漏洞利用 | 看我如何利用Kerberos EoP渗透你的Linux系统
  3. oracle的java路径,oracle学习----访问路径
  4. 服务器监听端口信息,服务器监听端口信息
  5. 在计算机术语中 将ALU控制器和,计算机组成原理试题与答案
  6. html5表单讲解,HTML5 表单新增元素与属性讲解
  7. Android:如何添加一个页面,如何跳转页面
  8. tomcat 不支持put 高版本_「MG6_DCT280」湿式七档双离合版本-性价比并不高
  9. c++的引用是什么意思?怎么回事?
  10. 数据预处理 参考sql