×

Java Programs

Java Practice

Java Program for Getting System UUID for Linux Machine

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.

Java Most Popular & Searched Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.