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 import oshi.util.tuples.Pair;
12
13
14
15
16 @ThreadSafe
17 public final class Dmidecode {
18
19 private Dmidecode() {
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
56
57
58
59
60
61
62
63
64 public static String querySerialNumber() {
65
66 if (UserGroupInfo.isElevated()) {
67 String marker = "Serial Number:";
68 for (String checkLine : ExecutingCommand.runNative("dmidecode -t system")) {
69 if (checkLine.contains(marker)) {
70 return checkLine.split(marker)[1].trim();
71 }
72 }
73 }
74 return null;
75 }
76
77
78
79
80
81
82 public static String queryUUID() {
83
84 if (UserGroupInfo.isElevated()) {
85 String marker = "UUID:";
86 for (String checkLine : ExecutingCommand.runNative("dmidecode -t system")) {
87 if (checkLine.contains(marker)) {
88 return checkLine.split(marker)[1].trim();
89 }
90 }
91 }
92 return null;
93 }
94
95
96
97
98
99
100 public static Pair<String, String> queryBiosNameRev() {
101 String biosName = null;
102 String revision = null;
103
104
105 if (UserGroupInfo.isElevated()) {
106 final String biosMarker = "SMBIOS";
107 final String revMarker = "Bios Revision:";
108
109 for (final String checkLine : ExecutingCommand.runNative("dmidecode -t bios")) {
110 if (checkLine.contains(biosMarker)) {
111 String[] biosArr = ParseUtil.whitespaces.split(checkLine);
112 if (biosArr.length >= 2) {
113 biosName = biosArr[0] + " " + biosArr[1];
114 }
115 }
116 if (checkLine.contains(revMarker)) {
117 revision = checkLine.split(revMarker)[1].trim();
118
119 break;
120 }
121 }
122 }
123 return new Pair<>(biosName, revision);
124 }
125 }