Get System Information of a Remote Machine (Using Java)

前端 未结 7 1756
天命终不由人
天命终不由人 2020-12-21 13:52

As the question\'s title says, I want to get the system information (like OS name, version, etc.) of a remote system using Java. But before anyone answers this question, I j

相关标签:
7条回答
  • 2020-12-21 13:55

    Try to use low level networking API such SNMP and UPnP. SNMP need an agent activated/installed in the remote system and you will have this information on the MIB. And the UPnP can do that, (i don't know how exactly, but i'm sure that is can be done).

    0 讨论(0)
  • 2020-12-21 13:58

    well as mentioned above, you can try them. By the way after getting connected you can use following codes:(if you wish)

     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);
          }
       }
    
    0 讨论(0)
  • 2020-12-21 14:04

    For Windows you should be able to access WMI on the remote machine (with some ugly JNI glue), for UNIX systems I don't know of a way (unless you somehow have shell access, then you can probably try logging in via SSH and do a uname -a or similar). It's going to be a lot of work in either case and Java is hardly the right tool for that.

    0 讨论(0)
  • 2020-12-21 14:06

    You either need help from the remote system (i.e. an application running there that announces the data - which web browsers do, but only to the servers they visit) or access to low-level network APIs that allow a technique called OS fingerprinting. However, Java's network APIs are not low-level enough for that.

    0 讨论(0)
  • 2020-12-21 14:09

    You need to clarify what you mean by "remote system" in this case - as in how are you communicating with it> Are we talking some form of HTTP? RMI? Applet running in a browser?

    Generally, however, the answer is "No, it's not possible".

    0 讨论(0)
  • 2020-12-21 14:12

    You either need help from the remote system (i.e. an application running there that announces the data - which web browsers do, but only to the servers they visit) or access to low-level network APIs that allow a technique called OS fingerprinting. However, Java's network APIs are not low-level enough for that.

    0 讨论(0)
提交回复
热议问题