栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Java中从客户端获取uuid或mac地址?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Java中从客户端获取uuid或mac地址?

我写了自己的方法来解决我的问题。在这里,是否有人需要代码来查找同一网络中的MAC地址。在Win 7和Mac OS X
10.8.2上无需任何管理员权限即可为我工作

Pattern macpt = null;private String getMac(String ip) {    // Find OS and set command according to OS    String OS = System.getProperty("os.name").toLowerCase();    String[] cmd;    if (OS.contains("win")) {        // Windows        macpt = Pattern     .compile("[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-[0-9a-f]+");        String[] a = { "arp", "-a", ip };        cmd = a;    } else {        // Mac OS X, Linux        macpt = Pattern     .compile("[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+");        String[] a = { "arp", ip };        cmd = a;    }    try {        // Run command        Process p = Runtime.getRuntime().exec(cmd);        p.waitFor();        // read output with BufferedReader        BufferedReader reader = new BufferedReader(new InputStreamReader(     p.getInputStream()));        String line = reader.readLine();        // Loop trough lines        while (line != null) { Matcher m = macpt.matcher(line); // when Matcher finds a Line then return it as result if (m.find()) {     System.out.println("Found");     System.out.println("MAC: " + m.group(0));     return m.group(0); } line = reader.readLine();        }    } catch (IOException e1) {        e1.printStackTrace();    } catch (InterruptedException e) {        e.printStackTrace();    }    // Return empty string if no MAC is found    return "";}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570363.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号