SIGAR (full Name System Information Gatherer and Reporter, which is the Systems information Collection Report), provides an open source, cross-platform API for collecting computer hardware and operating system information (the API's underlying interface is written in C). This article shows you how to get operating system information with the SIGAR API:
Package Com.ghj.packageoftest;import Java.net.inetaddress;import Org.hyperic.sigar.operatingsystem;import Org.hyperic.sigar.sigar;import org.hyperic.sigar.sigarexception;import org.hyperic.sigar.who;/** * with SIGAR API gets operating System Information * * @author Gaohuanjie */public class Ostool {public static void main (string[] args) throws Sigarexception { SIGAR SIGAR = new SIGAR ()///takes the name of the current operating system String hostname = ""; try {hostname = Inetaddress.getlocalhost (). GetHostName ( );} catch (Exception e) {hostname = Sigar.getnetinfo (). GetHostName (); SYSTEM.OUT.PRINTLN (hostname);//Get information about the current operating system operatingsystem OperatingSystem = Operatingsystem.getinstance (); System.out.println ("OperatingSystem arch:" + operatingsystem.getarch ());//Os kernel type: 386, 486, 586 et x86System.out.println ("OperatingSystem Cpuendian:" + Operatingsystem.getcpuendian ());//system.out.println (" OperatingSystem Datamodel: "+ Operatingsystem.getdatamodel ());//system.out.println (" OperatingSystem Description: "+ Operatingsystem.getdescription ());//SystemDescription System.out.println ("OperatingSystem machine:" + operatingsystem.getmachine ());//System.out.println (" OperatingSystem Name: "+ operatingsystem.getname ());//Os type System.out.println (" OperatingSystem patchlevel: "+ Operatingsystem.getpatchlevel ());//Os patch level SYSTEM.OUT.PRINTLN ("OperatingSystem Vendor:" + Operatingsystem.getvendor ());//Os Vendor System.out.println ("OperatingSystem vendorcodename:" + Operatingsystem.getvendorcodename ());//Supplier Code name SYSTEM.OUT.PRINTLN ("OperatingSystem vendorname:" + Operatingsystem.getvendorname ());//OS Vendor name System.out.println ("OperatingSystem vendorversion:" + Operatingsystem.getvendorversion ());//OS Vendor version System.out.println ("OperatingSystem version:" + Operatingsystem.getversion ());//operating system version number//Get user information in the current system process table who whoarray [] = Sigar.getwholist (); if (Whoarray! = null) { for (int i = 0; i < whoarray.length; i++) {who = Whoarray[i]; System.out.println ("\n~~~~~~~~~" + i + "~~~~~~~~~~~~"); System.out.println ("Who device:"+ Who.getdevice ()); System.out.println ("Who host:" + Who.gethost ()); System.out.println ("Who Time:" + who.gettime ()); System.out.println ("Who User:" + who.getuser ());//user name in the current system process table}}sigar.close ();}}
【
0 min Download Sample project】
Get operating System information with the SIGAR API