1
2
3
4
5 package oshi.driver.linux;
6
7 import oshi.annotation.concurrent.ThreadSafe;
8 import oshi.util.ExecutingCommand;
9 import oshi.util.ParseUtil;
10 import oshi.util.UserGroupInfo;
11
12
13
14
15 @ThreadSafe
16 public final class Lshw {
17
18 private Lshw() {
19 }
20
21 private static final String MODEL;
22 private static final String SERIAL;
23 private static final String UUID;
24 static {
25 String model = null;
26 String serial = null;
27 String uuid = null;
28
29 if (UserGroupInfo.isElevated()) {
30 String modelMarker = "product:";
31 String serialMarker = "serial:";
32 String uuidMarker = "uuid:";
33
34 for (String checkLine : ExecutingCommand.runNative("lshw -C system")) {
35 if (checkLine.contains(modelMarker)) {
36 model = checkLine.split(modelMarker)[1].trim();
37 } else if (checkLine.contains(serialMarker)) {
38 serial = checkLine.split(serialMarker)[1].trim();
39 } else if (checkLine.contains(uuidMarker)) {
40 uuid = checkLine.split(uuidMarker)[1].trim();
41 }
42 }
43 }
44 MODEL = model;
45 SERIAL = serial;
46 UUID = uuid;
47 }
48
49
50
51
52
53
54 public static String queryModel() {
55 return MODEL;
56 }
57
58
59
60
61
62
63 public static String querySerialNumber() {
64 return SERIAL;
65 }
66
67
68
69
70
71
72 public static String queryUUID() {
73 return UUID;
74 }
75
76
77
78
79
80
81 public static long queryCpuCapacity() {
82 String capacityMarker = "capacity:";
83 for (String checkLine : ExecutingCommand.runNative("lshw -class processor")) {
84 if (checkLine.contains(capacityMarker)) {
85 return ParseUtil.parseHertz(checkLine.split(capacityMarker)[1].trim());
86 }
87 }
88 return -1L;
89 }
90 }