Q:

Java Program for Getting System UUID for Linux Machine

0

Java Program for Getting System UUID for Linux Machine

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

This java program will get and print the system UUID for Linux Machine.

package com.includehelp;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Program to get System UUID Number for linux Machine (Root USer Login is Req for run this program)
 * @author includehelp
 */
public class LinuxSystemUUID {
    
    /**
     * Method for get System UUID for Linux Machine
     * @return 
     */
    static String getLinuxSystem_UUID() {
        String command = "dmidecode -s system-uuid";
        String uuid = null; 
        try {   
            Process SerNumProcess = Runtime.getRuntime().exec(command);
            BufferedReader sNumReader = new BufferedReader(new InputStreamReader(SerNumProcess.getInputStream()));
            uuid = sNumReader.readLine().trim();
            SerNumProcess.waitFor();
            sNumReader.close();
        }
        catch (Exception ex) {
            System.err.println("Linux UUID Exp : "+ex.getMessage());
            uuid =null;
        }
        finally {
            return uuid;
        }       
    }
    
    public static void main(String[] args) {
        String system_uuid  =getLinuxSystem_UUID();
        System.out.println("Linux System UUID Number : "+system_uuid);
    }
    
}

Output

Run at your Linux system.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now