这个例子使用了J2SE5.0的ProcessBuilder类执行外部的程序,相对于 Runtime.exec ,它更方便,可以设置环境变量等。
package com.kuaff.jdk5package;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class ProcessBuilderShow
{
public static List getPhysicalAddress()
{
Process p = null;
//物理网卡列表
List address = new ArrayList();
try
{
//执行ipconfig /all命令
p = new ProcessBuilder("ipconfig", "/all").start();
}
catch (IOException e)
{
return address;
}
byte[] b = new byte[1024];
StringBuffer sb = new StringBuffer();
//读取进程输出值
InputStream in = p.getInputStream();
try
{
while (in.read(b)>0)
{
sb.append(new String(b));
}
}
catch (IOException e1)
{
}
finally
{
try
{
in.close();
}
catch (IOException e2)
{
}
}
//以下分析输出值,得到物理网卡
String rtValue = sb.substring(0);
int i = rtValue.indexOf("Physical Address. . . . . . :");
while(i>0)
{
rtValue = rtValue.substring(i + "Physical Address. . . . . . . :".length());
address.add(rtValue.substring(0,18));
i = rtValue.indexOf("Physical Address. . . . . . . :");
}
return address;
}
public static void main(String[] args)
{
List address = ProcessBuilderShow.getPhysicalAddress();
for(String add:address)
{
System.out.printf("物理网卡地址:%s%n", add);
}
}
}
Windows下读取网卡物理地址
相关文章
- Windows 7 下如何调整网卡的优先级
- Windows10下如何提升双网卡提升网速,叠加网卡,跃点数
- windows下多个网卡正常上网小技巧
- 在windows下创建繁体中文文件名读取出来为乱码的解决方案
- windows下删除虚拟网卡/物理网卡/网卡组/交换机
- Windows以及Linux下双网卡内外网同时使用、设置域名解析优先级的方法 - newflypig
- Broadcom有线网卡在Windows 8/8.1/10下使用系统自带驱动会断网的解决办法
- 踩坑事件:windows操作系统下的eclipse中编写SparkSQL不能从本地读取或者保存parquet文件
- 在Windows下使用TinyXML-2读取UTF-8编码包含中文字符的XML文件
- Windows下Ruby+Watir自动化测试的环境搭建及数据读取