您的位置:首页 > 运维架构 > Shell

java执行shell命令 获取ip配置信息

2013-02-22 21:24 756 查看
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通过ProcessBuilder执行本地shell命令 获取ip配置信息 - java代码库 - 云代码 http://yuncode.net/code/c_50a5e9ef2258c96
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐