代码之家  ›  专栏  ›  技术社区  ›  Kirtan

获取远程机器的系统信息(使用Java)

  •  2
  • Kirtan  · 技术社区  · 17 年前

    编辑:Java应用程序将是一个桌面应用程序,它必须有凭据才能登录到远程系统,但不会使用HTTP/RMI。

    7 回复  |  直到 17 年前
        1
  •  5
  •   Joey Gumbo    17 年前

    对于Windows,您应该能够访问远程计算机上的WMI(使用一些难看的JNI胶水),对于UNIX系统,我不知道有什么方法(除非您有shell访问权限,否则您可能可以尝试通过SSH登录并执行 uname -a 或类似)。无论哪种情况,这都是一项艰巨的任务,而Java几乎不是合适的工具。

        2
  •  4
  •   Manjeet    14 年前

    正如上面提到的,你可以试试。顺便说一句,连接后,您可以使用以下代码:(如果您愿意)

     import java.util.Properties;
      public class GetCompleteSystemInfo {
    
    public static void main(String args[]) {
        //1.Get Java Runtime
        Runtime runtime = Runtime.getRuntime();
        System.out.println("Runtime=" + Runtime.getRuntime());
    
        //2. Get Number of Processor availaible to JVM
        int numberOfProcessors = runtime.availableProcessors();
        System.out.println(numberOfProcessors + " Processors ");
    
        //2. Get FreeMemory, Max Memory and Total Memory
        long freeMemory = runtime.freeMemory();
        System.out.println("Bytes=" + freeMemory + " |KB=" + freeMemory / 1024 + " |MB=" + (freeMemory / 1024) / 1024+" Free Memory in JVM");
    
        long maxMemory = runtime.maxMemory();
        System.out.println(maxMemory + "-Bytes " + maxMemory / 1024 + "-KB  " + (maxMemory / 1024) / 1024 + "-MB " + " Max Memory Availaible in JVM");
    
        long totalMemory = runtime.totalMemory();
        System.out.println(totalMemory + "-Bytes " + totalMemory / 1024 + "-KB " + (totalMemory / 1024) / 1024 + "-MB " + " Total Memory Availaible in JVM");
    
    
        //3. Suggest JVM to Run Garbage Collector
        runtime.gc();
    
        //4. Suggest JVM to Run Discarded Object Finalization
        runtime.runFinalization();
    
        //5. Terminate JVM
        //System.out.println("About to halt the current jvm");//not to be run always
        //runtime.halt(1);
        // System.out.println("JVM Terminated");
    
        //6. Get OS Name
        String strOSName = System.getProperty("os.name");
        if (strOSName != null) {
            if (strOSName.toLowerCase().indexOf("windows") != -1) {
                System.out.println("This is "+strOSName);
            } else {
                System.out.print("Can't Determine");
            }
        }
    
        //7. Get JVM Spec
        String strJavaVersion = System.getProperty("java.specification.version");
        System.out.println("JVM Spec : " + strJavaVersion);
        //8. Get Class Path
        String strClassPath = System.getProperty("java.class.path");
        System.out.println("Classpath: " + strClassPath);
    
        //9. Get File Separator
        String strFileSeparator = System.getProperty("file.separator");
        System.out.println("File separator: " + strFileSeparator);
    
        //10. Get System Properties
        Properties prop = System.getProperties();
        System.out.println("System Properties(detail): " + prop);
    
        //11. Get System Time
        long lnSystemTime = System.currentTimeMillis();
        System.out.println("Milliseconds since midnight, January 1, 1970 UTC : " + lnSystemTime + "\nSecond=" + lnSystemTime / 1000 + "\nMinutes=" + (lnSystemTime / 1000) / 60 + ""
                + "\nHours=" + ((lnSystemTime / 1000) / 60) / 60 + "\nDays=" +   (((lnSystemTime / 1000) / 60) / 60) / 24 + "\nYears=" + ((((lnSystemTime / 1000) / 60) /  60) / 24) / 365);
          }
       }
    
        3
  •  2
  •   ChssPly76    17 年前

    在这种情况下,您需要澄清“远程系统”的含义,例如您如何与它通信>我们谈论的是某种形式的HTTP吗?RMI?小程序在浏览器中运行?

    然而,一般来说,答案是“不,这是不可能的”。

        4
  •  1
  •   Jim Ferrans    17 年前

    这是监控由数十台或数百台机器组成的大型站点时常见的问题。有一些开源解决方案,比如 Zenoss 和 Nagios .SNMP也是该领域广泛支持的标准(并且有方法将它们连接到基于Java的“仪表板”中)。

        5
  •  0
  •   Michael Borgwardt    17 年前

    您要么需要远程系统的帮助(即在那里运行的宣布数据的应用程序,web浏览器会这样做,但只对它们访问的服务器),要么需要访问低级网络API,这些API允许一种称为 OS fingerprinting 然而,Java的网络API还不够低级。

        6
  •  0
  •   asis    16 年前

    你要么需要远程系统的帮助(即在那里运行的一个宣布数据的应用程序——网络浏览器会这样做,但只对它们访问的服务器),要么需要访问低级网络API,这种API允许一种称为操作系统指纹识别的技术。然而,Java的网络API还不够低级。

        7
  •  0
  •   imanis_tn    14 年前

    尝试使用低级别的网络API,如SNMP和UPnP。 SNMP需要在远程系统中激活/安装代理,您将在MIB上获得此信息。 UPnP可以做到这一点(我不知道具体是怎么做到的,但我相信这是可以做到的)。