在我们的部分代码中,我试图将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地址
发布评论