简体   繁体   中英

How can i find the computer type in Linux using Java?

How can i find the computer type in Linux using Java ? I need to find out if the device is a laptop/desktop/server/virtual machine.

I managed to find out if the computer is a virtual machine if it is VMWare.

Process virtual = Runtime.getRuntime().exec("sudo dmidecode -s system-manufacturer");
                BufferedReader virmar = new BufferedReader(
                        new InputStreamReader(virtual.getInputStream()));
                String s11;
                while ((s11 = virmar.readLine()) != null) {
                    virtualm = s11;
                    vmName = virtualm; 
                    if (s11.contains("VMware")) {
                        virtualma = "1";
                    } else {
                        virtualma = "";
                    }
            }

dmidecode has chassis-type to specify this information:

sudo dmidecode --string chassis-type

On the two systems I have it returns Mini Tower and Space-saving .

Microsoft documents the known chassis types .

I develop an inventory software and i need to know the workstation type. I managed to solve this using:

            String[] type = {"Laptop", "Notebook", "Portable", "Sub Notebook"};

            ....

            String cmd1[] = {"/bin/sh","-c","lsb_release -a | grep -i Description"};
            Runtime runsv = Runtime.getRuntime();
            Process prsv = runsv.exec(cmd1);
            BufferedReader sv = new BufferedReader(new InputStreamReader(
                    prsv.getInputStream()));
            String line1;
            while ((line1 = sv.readLine()) != null) {
                server = line1;

            }

            String cmd = "sudo dmidecode --string chassis-type";
            Runtime run = Runtime.getRuntime();
            Process pr = run.exec(cmd);
            BufferedReader comt = new BufferedReader(new InputStreamReader(
                    pr.getInputStream()));
            String line;
            while ((line = comt.readLine()) != null) {
                getcomputerType = line;
            }
            if (getcomputerType.equals(type)) {
                compType = "2";
            } else {
                if (server.equals("Server")) {
                compType = "3";
                }
                else{
                    compType = "1";
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM