-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSystemID.java
More file actions
94 lines (83 loc) · 3.02 KB
/
SystemID.java
File metadata and controls
94 lines (83 loc) · 3.02 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package MedX;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
public class SystemID {
/**
* Method for get System Motherboard Serial Number
* @return MAC Address
*/
public static String getSystemMotherBoard_SerialNumber(){
try{
String OSName= System.getProperty("os.name");
if(OSName.contains("Windows")){
return (getWindowsMotherboard_SerialNumber());
}
else{
return (GetLinuxMotherBoard_serialNumber());
}
}
catch(Exception E){
System.err.println("System MotherBoard Exp : "+E.getMessage());
return null;
}
}
/**
* Method for get Windows Machine MotherBoard Serial Number
* @return
*/
private static String getWindowsMotherboard_SerialNumber() {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs =
"Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_BaseBoard\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.SerialNumber \n"
+ " exit for ' do the first cpu only! \n"
+ "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception E){
System.err.println("Windows MotherBoard Exp : "+E.getMessage());
}
return result.trim();
}
/**
* Method for get Linux Machine MotherBoard Serial Number
* @return
*/
private static String GetLinuxMotherBoard_serialNumber() {
String command = "dmidecode -s baseboard-serial-number";
String sNum = null;
try {
Process SerNumProcess = Runtime.getRuntime().exec(command);
BufferedReader sNumReader = new BufferedReader(new InputStreamReader(SerNumProcess.getInputStream()));
sNum = sNumReader.readLine().trim();
SerNumProcess.waitFor();
sNumReader.close();
}
catch (Exception ex) {
System.err.println("Linux Motherboard Exp : "+ex.getMessage());
sNum =null;
}
return sNum;
}
public static void main(String[] args) {
String motherBoard_SerialNumber = getSystemMotherBoard_SerialNumber();
System.out.println("MotherBoard Serial Number : "+motherBoard_SerialNumber);
}
}