我想知道如何获取我的应用程序安装的PC的唯一标识符。我在here中提到了一些问题。但我无法使用它。请通过示例代码或任何有用的链接告诉我如何在Java中完成它。(至少如何在Java中获取系统详细信息)谢谢
答案 0 :(得分:1)
您可以使用系统的mac地址,每个系统都有唯一的mac地址。
/*
* Get NetworkInterface for the current host and then read the
* hardware address.
*/
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
/*
* Extract each array of mac address and convert it to hexa with the
* following format 08-00-27-DC-4A-9E.
*/
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
}
} else {
System.out.println("Address doesn't exist or is not accessible.");
}
} else {
System.out.println("Network Interface for the specified address is not found.");
}
答案 1 :(得分:1)
不稳定输出的不稳定的想法,注意到你收到了正确的计算机&amp;用户信息,PC的唯一标识符和更自信的结果返回HW FireWall后面的Intranet(非Interner)中的计算机
问题:
Novell,AD可以添加详细的UserInfo,而某些计算机(所有HP / Compaq)都不会返回硬件配置
private void getPcInfo() {
Enumeration<?> interfaces = null;
try {
PcLogName = InetAddress.getLocalHost().getHostName();
InetAddress local = InetAddress.getLocalHost();
InetAddress[] all_local = InetAddress.getAllByName(local.getHostName());
LinkedList<InetAddress> list = new LinkedList<InetAddress>();
//System.out.println("PcLogName " + PcLogName);
//System.out.println("PcLogName " + list);
try {
interfaces = NetworkInterface.getNetworkInterfaces();
////System.out.println("NetworkInterface " + interfaces);
} catch (SocketException ex) {
Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
}
while (interfaces.hasMoreElements()) {
NetworkInterface card = (NetworkInterface) interfaces.nextElement();
////System.out.println("NetworkInterface NetCard " + card);
Enumeration<?> addresses = card.getInetAddresses();
////System.out.println("NetCard Name " + addresses);
if (addresses == null) {
continue;
}
while (addresses.hasMoreElements()) {
InetAddress address = (InetAddress) addresses.nextElement();
list.add(address);
//System.out.println("Add Address : " + address);
}
}
//System.out.println("IP's Address " + list);
} catch (UnknownHostException ex) {
Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
}
PcLogUser = System.getProperty("user.name");
//System.out.println("PcLogUser : " + PcLogUser);
WinUser = System.getenv("USER");
//System.out.println("WinUser : " + WinUser);
WinDsn = System.getenv("USERDOMAIN");
//System.out.println("WinDsn : " + WinDsn);
WinUserName = System.getenv("USERNAME");
//System.out.println("WinUserName : " + WinUserName);
WinPath = System.getenv("USERPROFILE");
//System.out.println("WinPath : " + WinPath);
ComputerName = System.getenv("COMPUTERNAME");
//System.out.println("ComputerName : " + ComputerName);
PcInfo = System.getenv("System Model");
//System.out.println("PcInfo : " + PcInfo);
}
如何获取MAC here
答案 2 :(得分:1)