`
liudunxu2
  • 浏览: 30659 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
文章分类
社区版块
存档分类
最新评论

java获取系统相关信息(来自于gecko的SystemUtils,RemotiingUtils工具类)

 
阅读更多

1 判断是否为linux系统

public static final String OS_NAME = System.getProperty("os.name");
        if (OS_NAME != null && OS_NAME.toLowerCase().indexOf("linux") >= 0) { 
            isLinuxPlatform = true; 
        }

2 获取cpu个数

   /**
     * 默认为CPU个数-1,留一个CPU做网卡中断
     * 
     * @return
     */
    public static int getSystemThreadCount() {
        final int cpus = getCpuProcessorCount();
        final int result = cpus - 1;
        return result == 0 ? 1 : result;
    }


    public static int getCpuProcessorCount() {
        return Runtime.getRuntime().availableProcessors();
    }

3 获取jdk版本信息

 public static final String JAVA_VERSION = System.getProperty("java.version");
    private static boolean isAfterJava6u4Version = false;
    static {
        if (JAVA_VERSION != null) {
            // java4 or java5
            if (JAVA_VERSION.indexOf("1.4.") >= 0 || JAVA_VERSION.indexOf("1.5.") >= 0) {
                isAfterJava6u4Version = false;
            }
            else if (JAVA_VERSION.indexOf("1.6.") >= 0) {
                final int index = JAVA_VERSION.indexOf("_");
                if (index > 0) {
                    final String subVersionStr = JAVA_VERSION.substring(index + 1);
                    if (subVersionStr != null && subVersionStr.length() > 0) {
                        try {
                            final int subVersion = Integer.parseInt(subVersionStr);
                            if (subVersion >= 4) {
                                isAfterJava6u4Version = true;
                            }
                        }
                        catch (final Exception e) {

                        }
                    }
                }
                // after java6
            }
            else {
                isAfterJava6u4Version = true;
            }
        }
    }

4 获取本机ip地址

 // 遍历网卡,查找一个非回路ip地址并返回,如果没有找到,则返回InetAddress.getLocalHost()
    public static InetAddress getLocalHostAddress() throws UnknownHostException, SocketException {
        final Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
        InetAddress ipv6Address = null;
        while (enumeration.hasMoreElements()) {
            final NetworkInterface networkInterface = enumeration.nextElement();
            final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
            while (en.hasMoreElements()) {
                final InetAddress address = en.nextElement();
                if (!address.isLoopbackAddress()) {
                    if (address instanceof Inet6Address) {
                        ipv6Address = address;
                    }
                    else {
                        // 优先使用ipv4
                        return address;
                    }
                }
            }

        }
        // 没有ipv4,则使用ipv6
        if (ipv6Address != null) {
            return ipv6Address;
        }
        return InetAddress.getLocalHost();
    }
分享到:
评论

相关推荐

    Gecko

    Gecko

    JAVA编写的Gecko内核浏览器源码

    用JAVA编写的多种浏览器Demo程序,集成火狐的Gecko内核、调用IE内核

    gecko-sdk.rar_Gecko SDK_gecko

    测试,Gecko SDK 支持win7,最新版本

    JavaNIO的通讯组件Gecko-Java.zip

    Gecko是一个Java NIO的通讯组件,它在一个轻量级的NIO框架的基础上提供了更高层次的封装和功能。支持的RPC调用方式包括RR(request-response)和pipeline 特性: 可插拔的协议设计 连接池 分组管理和负载均衡 ...

    软件测试geckodriver驱动安装包

    在Selenium测试脚本中,需要将geckodriver.exe驱动程序的路径设置为系统路径,在创建Firefox WebDriver实例时通过指定geckodriver.exe文件路径和Firefox二进制文件路径,从而启动Firefox浏览器并运行测试脚本。gecko...

    GeckoBrowser_delphi_gecko_browser_

    gecko browser for delphi application and control

    android基于gecko引擎的浏览器示例

    在android上基于gecko引擎的浏览器简单实现,解决在低版本android系统webview对ES6支持不好的问题。

    geckodriver

    geckodriver geckodriver geckodriver geckodriver

    geckodriver-v0.14.0

    geckodriver-v0.14.0 支持linux和windows 64位

    geckodriver-v0.16.0-win64

    自动化执行,selenium3 firefox所需驱动为geckodriver-v0.16.0-win64

    geckodriver.exe(包含32和64位)

    分享一下火狐浏览器驱动程序geckodriver,好不容易在github上下载下来,可以很方便获取网页信息及控制网页

    geckodriver.exe

    java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see ...

    Gecko浏览器内核

    Gecko(Firefox内核) Gecko:Netscape6开始采用的内核,后来的Mozilla FireFox(火狐浏览器) 也采用了该内核,Gecko的特点是代码完全公开,因此,其可开发程度很高,全世界的程序员都可以为其编写代码,增加功能。...

    geckodriver.exe4个版本下载

    由于webdriver在不同的firefox版本中,需要的geckodriver.exe版本也不同,所以需要对照版本下载不同的geckodriver.exe,资源中包括了geckodriver.exe 15、16、19、23 4个版本的资源

    geckodriver-0.21.0

    火狐浏览器用可执行程序GeckoDriver.exe的方式执行WebDriver协议。所有的测试脚本都通过GeckoDriver来执行

    geckodriver 64位

    geckodriver 64位

    geckodriver-v0.11.1-win32位

    python selenim 报错: 'geckodriver' executable needs to be in PATH需下载geckodriver解压放在C:\Python27即可

    skybound.gecko.rar

    skybound.gecko.dll文件,skybound.gecko.dll文件 skybound.gecko.dll文件免费下载

Global site tag (gtag.js) - Google Analytics