2010. 3. 18. 14:22

자바로 MAC address 구해보기

import java.io.*;

public class MacAddressTest { 
  public static void main(String args[]) throws Exception {
    Process process = Runtime.getRuntime().exec("ipconfig /all");

InputStream standardOutput = process.getInputStream(), standardError =     process.getErrorStream() ;
String output = ""; int c;

    while ((c = standardOutput.read()) != -1) { 
      output = output + new Character((char)c).toString(); 
    } 
    while ((c = standardError.read()) != -1) 
      standardOutput.close(); 
      standardError.close(); 

BufferedReader br = new BufferedReader(new StringReader(output)); String line = null; while ((line = br.readLine()) != null) { if (line.trim().startsWith("Physical Address")) { String mac = line.substring(line.indexOf(":")+1, line.length()).trim();
System.out.println("MAC Address : " + mac); } } } }