1. public static String getPhysicalAddress() { 
  2.     Process p = null
  3.  
  4.     try { 
  5.         // 执行ipconfig /all命令 
  6.         p = new ProcessBuilder("ipconfig""/all").start(); 
  7.     } catch (IOException e) { 
  8.         return ""
  9.     } 
  10.     byte[] b = new byte[1024]; 
  11.     int readbytes = -1
  12.     StringBuffer sb = new StringBuffer(); 
  13.     // 读取进程输出值 
  14.     InputStream in = p.getInputStream(); 
  15.     try { 
  16.         while ((readbytes = in.read(b)) != -1) { 
  17.             sb.append(new String(b, 0, readbytes)); 
  18.         } 
  19.  
  20.     } catch (IOException e1) { 
  21.     } finally { 
  22.         try { 
  23.             in.close(); 
  24.         } catch (IOException e2) { 
  25.         } 
  26.     } 
  27.  
  28.     return sb.toString(); 

转自:java通过ProcessBuilder执行本地shell命令 获取ip配置信息 - java代码库 - 云代码 http://yuncode.net/code/c_50a5e9ef2258c96