java的uuid在哪_如何在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 "";

}

2020-11-13

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值