获取mac地址又一方法
2012-11-28 09:06
162 查看
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); byte[] hardwareAddress = networkInterface.getHardwareAddress(); if (hardwareAddress != null) { for (int i = 0; i < hardwareAddress.length; i++) { System.out.print(String.format("%x", hardwareAddress[i])); if (i != hardwareAddress.length - 1) { System.out.print(":"); } } System.out.println(); } } 以前的方法 public static String[] getMacs() throws IOException { Runtime runtime = Runtime.getRuntime(); List<String> alMac = new ArrayList<String>(); BufferedReader rd = null; try { Process process = runtime.exec("ipconfig /all");//这种方法不能跨os, 只能根据不同的os写不同的命令 InputStream is = process.getInputStream(); rd = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = rd.readLine()) != null) { if (line.indexOf("物理地址") > -1 || line.toLowerCase().startsWith("physical address")) { int index = line.lastIndexOf(":"); if (line.length() - 1 >= index && index > -1) { String mac = line.substring(index + 1); alMac.add(mac); } } } } finally { if (rd != null) rd.close(); } return alMac.toArray(new String[0]); }
相关文章推荐
- ASP.NET获取IP与MAC地址的方法
- C++获取本地mac地址和网关mac地址方法
- wince下获取mac地址的简单方法!
- VC获取MAC地址的4种方法
- ASP.NET获取IP与MAC地址的方法
- python获取本机mac地址和ip地址的方法
- DOS命令下获取远程主机MAC地址的三种方法
- ASP.NET技术获取IP与MAC地址的方法
- Windows中获取本机MAC地址的方法
- ASP.NET获取IP与MAC地址的方法
- [译]获取系统网络MAC地址的三种方法
- 获取MAC地址多种方法,操作系统的 API 不一定适用。
- Android获取本机Mac地址及IP地址方法
- 获取MAC地址最有效方法作为软件加密时用到在不同系统平台下
- ASP.NET获取IP与MAC地址的方法
- C++获取本机MAC,IP,MASK地址的方法
- 在asp.net中获取mac地址的方法(C#后台获取的方法和前台Javascript(调用ActiveX)获取的方法)
- python获取本机mac地址和ip地址的方法
- DOS命令下获取远程主机MAC地址的三种方法
- Android6.0系统MAC地址获取的方法