String command = "cmd.exe /c ipconfig";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
String address = "";
while ((line = br.readLine()) != null) {
if (line.indexOf("Default Gateway") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
System.out.println(address);
我可以跟你说下我的思路要是还不懂得话可以百度HI我
利用Runtime.getRuntime().exec("ipconfig");执行的结果是个字符串,
再利用正则表达式,抽取 这一行你需要的内容
Default Gateway . . . . . . . . . : 192.168.0.1
明白吗?