document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.net.InetAddress;
  6. import java.net.NetworkInterface;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9.  
  10. /**
  11.  *
  12.  * @author Charleston Anjos
  13.  * @Version 2.0
  14.  * @Create 22/06/2013
  15.  */
  16. public class cComputador {
  17.    
  18.     public cComputador(){
  19.         System.out.println(this.IP());
  20.         System.out.println(this.HOST());
  21.         System.out.println(this.MAC());
  22.         System.out.println(this.usuario());
  23.        
  24.         try {
  25.             System.out.println(this.execCommand("ipconfig -all"));
  26.         } catch (IOException ex) {
  27.             Logger.getLogger(cComputador.class.getName()).log(Level.SEVERE, null, ex);
  28.         }
  29.     }
  30.    
  31.     public static void main(String[] args) {
  32.         cComputador pc = new cComputador();
  33.     }
  34.  
  35.     public String IP(){
  36.         //Cria uma variável do tipo Inet
  37.         InetAddress ip = null;
  38.  
  39.         try{
  40.             ip = InetAddress.getLocalHost(); //seta o endereço para o computador local
  41.         }catch(Exception e){
  42.             e.printStackTrace();//exceção
  43.         }
  44.  
  45.         return String.valueOf(ip.getHostAddress());//retorna o endereço de ip
  46.     }
  47.  
  48.     public String HOST(){
  49.         //Cria uma variável do tipo Inet
  50.         InetAddress ip = null;
  51.  
  52.         try{
  53.             ip = InetAddress.getLocalHost();//seta o endereço para o computador local
  54.         }catch(Exception e){
  55.             e.printStackTrace();//exceção
  56.         }
  57.  
  58.         return String.valueOf(ip.getHostName());//retorna o nome do computador
  59.     }
  60.  
  61.     public String MAC(){
  62.         String mac_retorno = null;//cria uma váriavel string para retornar o endereço mac
  63.  
  64.         try{
  65.             //cria um objeto do tipo network para pegar o ende
  66.             NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
  67.  
  68.             //guarda em um array o endereço do hardware (placa mãe)
  69.             byte[] mac = network.getHardwareAddress();
  70.  
  71.             //string imutável
  72.             StringBuilder sb = new StringBuilder();
  73.  
  74.             //faz um looping pegando os números do endereço mac e formata (mascara)
  75.             for (int i = 0; i < mac.length; i++) {
  76.                 //adiciona na string sb os dados (concatenação)
  77.                 sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
  78.             }
  79.  
  80.             //variavel mac_retorno recebe a string imutavel
  81.             mac_retorno = String.valueOf(sb);
  82.  
  83.         }catch(Exception e){
  84.             e.printStackTrace();//exceção
  85.         }
  86.  
  87.         //retorna o endereço obtivo
  88.         return mac_retorno;
  89.     }
  90.    
  91.     public String usuario(){
  92.         return System.getProperty("user.name");
  93.     }
  94.    
  95.     public synchronized static String execCommand(final String commandLine) throws IOException {  
  96.  
  97.         boolean success = false;  
  98.         String result;  
  99.  
  100.         Process p;  
  101.         BufferedReader input;  
  102.         StringBuffer cmdOut = new StringBuffer();  
  103.         String lineOut = null;  
  104.         int numberOfOutline = 0;  
  105.  
  106.         try {  
  107.  
  108.             p = Runtime.getRuntime().exec(commandLine);  
  109.  
  110.             input = new BufferedReader(new InputStreamReader(p.getInputStream()));  
  111.  
  112.             while ((lineOut = input.readLine()) != null) {  
  113.                 if (numberOfOutline > 0) {  
  114.                     cmdOut.append("\\n");  
  115.                 }  
  116.                 cmdOut.append(lineOut);  
  117.                 numberOfOutline++;  
  118.             }  
  119.  
  120.             result = cmdOut.toString();  
  121.  
  122.             success = true;  
  123.  
  124.             input.close();  
  125.  
  126.         } catch (IOException e) {  
  127.             result = String.format("Falha ao executar comando %s. Erro: %s", commandLine, e.toString());  
  128.         }  
  129.  
  130.         // Se não executou com sucesso, lança a falha  
  131.         if (!success) {  
  132.             throw new IOException(result);  
  133.         }  
  134.  
  135.         return result;  
  136.  
  137.     }  
  138. }
');