macaddress if (macAddressBytes != null && macAddressBytes.length > 5) { macAddress = String.format( "%1$02x%2$02x%3$02x%4$02x%5$02x%6$02x", macAddressBytes[0], macAddressBytes[1], macAddressBytes[2], macAddressBytes[3], macAddressBytes[4], macAddressBytes[5]).toUpperCase(); } InetAddress addr = InetAddress.getLocalHost(); this.cpuSerial = getCPUID(); this.hostName = addr.getHostName(); this.macAddress = macAddress; this.hostAddress = addr.getHostAddress(); this.virtualAdapter = netInter.isVirtual(); } catch (UnknownHostException e) { System.err.println(e); } catch (SocketException e) { System.err.println(e); } } public static synchronized ComputerInfo getIntance() { if (ci == null) { ci = new ComputerInfo(); } return ci; } public String getCpuSerial() { return cpuSerial; } public String getHostName() { return hostName; } public String getMacAddress() { return macAddress; } public String getHostAddress() { return hostAddress; } public boolean isVirtualAdapter() { return virtualAdapter; } public static String getCPUID() { String result = null; if (OS.OS == OS.WINDOWS) { result = getCPUIDForWindows(); } else if (OS.OS == OS.LINUX) { result = getCPUIDForLinux(); } return result; } private static String getCPUIDForWindows() { StringBuffer result = new StringBuffer(); try { File file = File.createTempFile("tmp", ".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); StringBuffer vbs = new StringBuffer(); vbs.append("On Error Resume Next \r\n\r\n"); vbs.append("strComputer = \".\" \r\n"); vbs.append("Set objWMIService = GetObject(\"winmgmts:\" _ \r\n"); vbs.append(" & \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\") \r\n"); vbs.append("Set colItems = objWMIService.ExecQuery(\"Select * from Win32_Processor\") \r\n "); vbs.append("For Each objItem in colItems\r\n "); vbs.append(" Wscript.Echo objItem.ProcessorId \r\n "); vbs.append(" exit for ' do the first cpu only! \r\n"); vbs.append("Next "); fw.write(vbs.toString()); 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.append(line); } input.close(); } catch (Exception e) { } if (result == null || result.toString().trim().length() < 1 ) { result = new StringBuffer(); return NO_CPU_ID; } return result.toString().trim(); } private static String getCPUIDForLinux() { String result = null; try { Process p = Runtime.getRuntime().exec("dmidecode -t 4"); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { if (line.length()>3 && line.substring(0, 3).equals(("ID:"))) { StringTokenizer tokenizer = new StringTokenizer(line, ":"); line = tokenizer.nextToken(); result = tokenizer.nextToken(); } } input.close(); if(result==null || result.trim().length()==0) { result=NO_CPU_ID; } } catch(Exception e){ System.err.println(e); } return result.trim(); } }A enum OS utilizada como dependenciaCrie um arquivo enum (nao e classe) chamado OS.java:public enum OS { WINDOWS("windows"), LINUX("linux"); public static final OS OS; private static DGLog logger = new DGLog(br.com.digicon.dnserver.util.OS.class); private String name; static { String tempOS = System.getProperty("os.name"); if(tempOS==null) { tempOS = "N/A"; } else { tempOS = tempOS.trim().toLowerCase(); } if(tempOS.indexOf(WINDOWS.name)!=-1){ OS = WINDOWS; } else if(tempOS.indexOf(LINUX.name)!=-1){ OS = LINUX; } else { OS=null; logger.error("O sistema operacional %s nao e compativel a aplicacao", tempOS); } } OS(String os) { name = os; } public String toString() { return this.name; } }Obs.: Esta classe e de autoria do Rafael Lima que contribuiu para a melhoria de ComputerInfo.Testes da classe ComputerInfoAgora vamos testar com um metodo main para isso: public static void main(String args[]) { ComputerInfo cii = ComputerInfo.getIntance(); System.out.println(cii.getCpuSerial()); System.out.println(cii.getHostAddress()); System.out.println(cii.getHostName()); System.out.println(cii.getMacAddress()); System.out.println(cii.isVirtualAdapter()); }ResultadosApos obter a instancia por meio de uma funcao singleton getInstance(), a serie de invocacoes de metodos para obtencao dos identificadores do computador gerou a seguinte sequencia de resultados:BFEBFBFF000300A9192.168.0.8BRE1010005056C00001falseBoa sorte!