- public static String getPhysicalAddress() {
- Process p = null;
- try {
- // 执行ipconfig /all命令
- p = new ProcessBuilder("ipconfig", "/all").start();
- } catch (IOException e) {
- return "";
- }
- byte[] b = new byte[1024];
- int readbytes = -1;
- StringBuffer sb = new StringBuffer();
- // 读取进程输出值
- InputStream in = p.getInputStream();
- try {
- while ((readbytes = in.read(b)) != -1) {
- sb.append(new String(b, 0, readbytes));
- }
- } catch (IOException e1) {
- } finally {
- try {
- in.close();
- } catch (IOException e2) {
- }
- }
- return sb.toString();
- }
转自: - java代码库 - 云代码 http://yuncode.net/code/c_50a5e9ef2258c96