NetworkInterface不会返回所有mac地址

编程入门 行业动态 更新时间:2024-10-28 06:34:12
本文介绍了NetworkInterface不会返回所有mac地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我们的部分代码中,我试图将Mac地址与我们的许可证文件绑定,并且遇到一个问题,即我用于弄清机器所有mac地址的代码未返回所有物理mac地址.这是获取所有mac地址的代码

In part of our code i am trying to bind a mac address with our license file and i am facing an issue that my code for figuring out all the mac addresses of the machine is not returning all the physical mac addresses. Here is the code to get all the mac addresses

public static Collection<String> getAllLocalMacAddresses() throws IOException { final Enumeration<NetworkInterface> inetAddresses = NetworkInterface.getNetworkInterfaces(); final Collection<String> addresses = new LinkedList<String>(); while(inetAddresses.hasMoreElements()){ final byte[] macBytes = inetAddresses.nextElement().getHardwareAddress(); if(macBytes == null) continue; addresses.add(getMacAddress(macBytes)); } return addresses; } static String getMacAddress(byte[] macBytes){ final StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < macBytes.length; i++){ strBuilder.append(String.format("%02X%s", macBytes[i], (i < macBytes.length - 1) ? ":" : "")); } return strBuilder.toString().toUpperCase(); }

这是我从这种方法中得到的结果

Here is the result that i get from this method

[, 00:00:00:00:00:00:00:E0, 00:26:B9:30:6D:CB, 00:26:B9:30:6D:CB, 00:00:00:00:00:00:00:E0, 00:26:B9:30:6D:CB, 02:26:B9:30:6D:C1, 00:26:B9:30:6D:CB, 00:00:00:00:00:00:00:E0]

"ipconfig/all"的输出显示了这些物理地址(如果需要,我可以粘贴此命令的输出)

The output from "ipconfig /all" shows me these physical addresses (i could paste the out put for this command if required)

00-26-B9-30-6D-C3 02-26-B9-30-6D-C1 00-26-B9-30-6D-C5 00-26-B9-30-6D-C9 00-26-B9-30-6D-CB 00-00-00-00-00-00-00-E0

现在,如果您看到Java代码没有返回地址"00-26-B9-30-6D-C3",并且还打印了三次地址"00:26:B9:30:6D:CB".任何想法为什么会发生这种情况,我该如何解决.

Now if you see the java code did not return the address "00-26-B9-30-6D-C3" and also printed the address "00:26:B9:30:6D:CB" thrice. Any idea why this would be happening and how can i fix it.

任何帮助将不胜感激:)

Any help will be deeply appreciated :)

推荐答案

尝试 docs.oracle/javase/6/docs/api/java/net/NetworkInterface.html#getSubInterfaces()-它可能是虚拟接口

Try docs.oracle/javase/6/docs/api/java/net/NetworkInterface.html#getSubInterfaces() - it could be a virtual interface

更多推荐

NetworkInterface不会返回所有mac地址

本文发布于:2023-11-05 16:07:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地址   NetworkInterface   mac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!