Java代码
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class Test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Properties pp = System.getProperties(); //获取系统的所有属性
pp.list(System.out);//打印所有的属性
String command = "cmd.exe /c ipconfig/all ";
Process p = Runtime.getRuntime().exec(command);//执行DOS程序
System.out.println(p);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
String address = "";
while ((line = br.readLine()) != null) {
System.out.println(line);
if (line.indexOf("Physical Address") > 0) {//如果有Physical Address字符串
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
System.out.println(address);
}
}
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class Test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Properties pp = System.getProperties(); //获取系统的所有属性
pp.list(System.out);//打印所有的属性
String command = "cmd.exe /c ipconfig/all ";
Process p = Runtime.getRuntime().exec(command);//执行DOS程序
System.out.println(p);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
String address = "";
while ((line = br.readLine()) != null) {
System.out.println(line);
if (line.indexOf("Physical Address") > 0) {//如果有Physical Address字符串
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
System.out.println(address);
}
}