Does anybody have a reliable way to get a good UID for linux os without generating one?
I’ve tried the following code and does not work.
I’ve tried the following code and does not work.
B4X:
#If java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Scanner;
import static javax.swing.JOptionPane.showMessageDialog;
private static String sn = null;
public static final String getLinuxSN() {
if (sn == null) {
readDmidecode();
}
if (sn == null) {
readLshal();
}
if (sn == null) {
throw new RuntimeException("Cannot find computer SN");
}
return sn;
}
private static BufferedReader read(String command) {
OutputStream os = null;
InputStream is = null;
Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
process = runtime.exec(command.split(" "));
} catch (IOException e) {
showMessageDialog(null, e);
throw new RuntimeException(e);
}
os = process.getOutputStream();
is = process.getInputStream();
try {
os.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return new BufferedReader(new InputStreamReader(is));
}
private static void readDmidecode() {
String line = null;
String marker = "Serial Number:";
BufferedReader br = null;
try {
br = read("dmidecode -t system");
while ((line = br.readLine()) != null) {
if (line.indexOf(marker) != -1) {
sn = line.split(marker)[1].trim();
break;
}
}
} catch (IOException e) {
showMessageDialog(null, e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
private static void readLshal() {
String line = null;
String marker = "system.hardware.serial =";
BufferedReader br = null;
try {
br = read("lshal");
while ((line = br.readLine()) != null) {
if (line.indexOf(marker) != -1) {
showMessageDialog(null, line);
sn = line.split(marker)[1].replaceAll("\\(string\\)|(\\')", "").trim();
break;
}
}
} catch (IOException e) {
showMessageDialog(null, e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
showMessageDialog(null, e);
throw new RuntimeException(e);
}
}
}
}
/**
* Method for get Linux Machine MotherBoard Serial Number
* @return
*/
public 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) {
showMessageDialog(null, ex.getMessage());
System.err.println("Linux Motherboard Exp : "+ex.getMessage());
sNum ="error";
}
return sNum;
}
#End If