在winXp下能获取MAC地址,在Vista系统下怎么获取不到啊?!

yrenyuan 2009-05-20 10:22:57
try {

Enumeration<NetworkInterface> el = NetworkInterface.getNetworkInterfaces();

while (el.hasMoreElements()) {

NetworkInterface ni = el.nextElement();
// MACを取得する
byte[] mac = ni.getHardwareAddress();

if (mac == null) {
continue;
}

builder = new StringBuilder();

for (byte b : mac) {
builder.append(hexByte(b));

// 16進法の文字列に"-"が追加する
builder.append("-");
}

// 指定文字列を削除する
builder.deleteCharAt(builder.length() - 1);

System.out.println("@@@@@@@@1==" + ni.isUp() + ":" + builder.toString().toUpperCase());
System.out.println("#########==" + ni.getDisplayName());
String strDisplayName = ni.getDisplayName();
int index = strDisplayName.indexOf(strWireless);

// ネットワークアダプタが使用中またWireLess以外の場合
if (ni.isUp() && index == -1) {
rtnMac = builder.toString().toUpperCase();
System.out.println("$$$$$$$$$==" + rtnMac);
break;
}
}
} catch (Exception exception) {
exception.printStackTrace();
}

return rtnMac;
}
...全文
185 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yrenyuan 2009-09-10
  • 打赏
  • 举报
回复
由于不同操作系统读取MAC地址的命令、以及命令输出格式的不同,所以该程序不能直接运用到其它系统。要移植到其它系统只需针对命令的输出格式进行修改。
yrenyuan 2009-09-02
  • 打赏
  • 举报
回复
由于不同操作系统读取MAC地址的命令、以及命令输出格式的不同,所以该程序不能直接运用到其它系统。要移植到其它系统只需针对命令的输出格式进行修改。

我可以利用先去操作系统的标志,在判断是什么操作系统后,做分支,利用各自的方法去MAC
yrenyuan 2009-09-02
  • 打赏
  • 举报
回复
因为在XP 和 vista下面,运行dos,所显示的物理地址的(MAC地址)长度不一样。所以,长度分别是36和32的。
marcblue 2009-05-20
  • 打赏
  • 举报
回复
public static String getMac() throws IOException
{
String command="ipconfig /all";
String mac=null;
Process proc=Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line=null;
while((line=reader.readLine())!=null)
{
if(line.indexOf("Physical Address")!=-1)
{
mac=line.substring(line.indexOf("Physical Address")+36, line.length());
break;
}
}
return mac;
}


Vista下需要改成:

if(line.indexOf(”物理地址”)!=-1)
{

mac=line.substring(line.indexOf(”物理地址”)+32, line.length());
break;

}
marcblue 2009-05-20
  • 打赏
  • 举报
回复
由于不同操作系统读取MAC地址的命令、以及命令输出格式的不同,所以该程序不能直接运用到其它系统。要移植到其它系统只需针对命令的输出格式进行修改。
brehme2007 2009-05-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 marcblue 的回复:]
Java codepublic static String getMac() throws IOException
{
String command="ipconfig /all";
String mac=null;
Process proc=Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line=null;
while((line=reader.readLine())!=null)
{
if(line.indexOf("Physical Address")!=-1)
{
mac=line.substring(line.indexOf("Physica…
[/Quote]
请问在winxp和vista下为啥要在读取索引后各加上36,和32.不明白。
VueScan 是一款功能强大的扫描应用程序,允许您使用平板或胶片扫描仪获取高质量的图像。如果您对扫描仪供应商提供的软件不满意,或者您想使用新功能进行改进,您应该尝试此程序。 扫描文档: 无论您需要扫描单页还是 100 页的书,VueScan 都有帮助您的工具。 - 使用平板和自动送纸器(ADF)进行扫描 - 扫描到 PDF(单页和多页) - 光学字符识别(OCR) - 自动颜色检测 - 小文档文件大小 - 自动校正文档纠偏 扫描照片: 你抽屉里有一个装满照片的盒子吗?您可以使用 VueScan 将它们放到您的计算机上。 - 使用平板和自动送纸器(ADF)进行扫描 - 扫描到 JPEG 或 TIFF - 预设照片大小 - 在平板上扫描多张照片 - 自动文件命名 扫描胶片和幻灯片: VueScan 是所有胶片和幻灯片扫描的终极工具。 - 几乎适用于所有的胶片/幻灯片扫描仪 - 扫描到 JPEG/TIFF/RAW - 红外除尘 - 颜色校正 - IT8 校准 - Photoshop 集成 支持系统Windows XPVistaWindows 7、Windows 8、Windows 10(32/64 位) v9.6.07 版本更新:2018年3月17日 - 改进了对 Windows 上的 WIA 扫描仪的支持 - 添加了对“首选项|查看器”使用脚本的支持 可在 Windows 上使用 .bat 文件 可在 Mac OS X 和 Linux 上使用 .sh 或 .csh 文件 - 添加了对某些爱普生文档扫描仪的更高分辨率扫描的支持 - 在爱普生扫描仪上使用灯盖更快地终止透明扫描 - 修复了一些其他小问题

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧