Nex*_*s2k 5 java uuid mac-address web-applications
我正在寻找基于Java的Web应用程序的解决方案来唯一地识别客户端.服务器与客户端在同一网络中,我认为使用MAC地址将是一个很好的解决方案.问题是我不能使用cookie,因为它们可以被客户端删除,我不能使用IP,因为他们可以发布一个新的DHCP租约续订.
所以我想回退到客户端的MAC地址.我知道没有java内置功能来获取MAC地址.是否有可以处理每个操作系统输出的库?(主Windows和Mac),因为我的Java应用程序在两个平台上运行.
或者是否有任何其他建议可以唯一识别网站和HTTP协议中的客户端?(可能是HTML5数据存储或其他)
我正在使用Java 1.7顺便说一句.
我不会强迫用户登录或以其他方式识别自己,我不会为客户端智能手机编写本机应用程序.
Nex*_*s2k 11
我写了自己的方法来解决我的问题.在这里,如果有人需要代码来在同一网络中找到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 "";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17803 次 |
| 最近记录: |