1
13693261870
2025-01-14 f4f42aeec935c554311841e9b1ed36917c85ddc1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.se.system.utils;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
 
@SuppressWarnings("ALL")
public class ServerSerialUtils {
    public ServerSerialUtils() {
    }
 
    /**
     * 执行Linux的shell获取Linux信息
     *
     * @param shell 命令
     * @return String Server信息
     * @throws Exception 默认异常
     */
    public static String getLinuxSerial(String[] shell) throws Exception {
        String serial = "";
        /** 使用dmidecode命令获取列号 */
        Process process = Runtime.getRuntime().exec(shell);
        process.getOutputStream().close();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = reader.readLine().trim();
        if (CommonUtils.isNotEmpty(line)) {
            serial = line;
        }
        reader.close();
        return serial;
    }
 
    /**
     * 执行windows的command获取Windows信息
     *
     * @param command 命令
     * @return String Server信息
     * @throws Exception 默认异常
     */
    public static String getWindowsSerial(String command) throws Exception {
        String serial = "";
        /** 使用WMIC获取序列号 */
        Process process = Runtime.getRuntime().exec(command);
        process.getOutputStream().close();
        Scanner scanner = new Scanner(process.getInputStream());
        if (scanner.hasNext()) {
            scanner.next();
        }
        if (scanner.hasNext()) {
            serial = scanner.next().trim();
        }
        scanner.close();
        return serial;
    }
}