生成特定计算机唯一的ID [英] Generating ID unique to a particular computer

查看:210
本文介绍了生成特定计算机唯一的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
生成唯一硬件ID的可靠方法

Possible Duplicate:
Reliable way of generating unique hardware ID

正在尝试生成特定计算机唯一的ID.该ID不会随机生成.这将基于计算,以便为计算机A生成的ID将是固定的,并且对于计算机A是唯一的.每次在计算机A上执行程序时,它将继续生成相同的ID,并且在另一台计算机上执行时,它将生成该计算机唯一的另一个ID.这是为了确保两台​​计算机没有相同的ID.

Am trying to generate an ID that will be unique to a particular computer. The ID will not be generated randomly. It will be calculation based, such that the ID generated for computer A will be fixed and unique to computer A. Everytime the program is executed on computer A, it will continue to generate the same ID and when executed on another computer, it will generate another ID unique to that computer. This is to ensure that two computers don't have the same ID.

我的挑战:为了使我的程序能够生成计算机唯一的ID,它需要根据执行该计算机的计算机唯一的种子来执行计算.

My Challenge: For my program to be able to generate an ID unique to a computer, it needs to perform the calculation based on a seed unique to the computer executing it.

我的问题:如何获得计算机唯一的值,以便可以将其用作ID生成程序中的种子?

My Question: How can i get a value unique to a computer, so that i can use the value as a seed in the ID generation program?

是否有可能从该计算机特有的计算机硬件(例如主板)中获得价值?这样,只要不更换计算机的主板,该值很可能就不会改变.

Is it possible to get a value from a computer's hardware(eg motherboard) that is unique to that computer? That way, the value is most likely not to change as long as the computer's motherboard is not replaced.

推荐答案

MAC地址?多数民众赞成(出于实际目的)对于每个NIC都是唯一的,因此即使用户是双重引导,它也保证了可重复性. .当然,很少有人交易卡的情况,但是与其他指标结合(不仅可以使用此功能,因为可以更改网卡),还是有可能的.

MAC address? Thats (for practical purposes) unique to every NIC so it guarantee's reproducibility even if the user is dual booting. Sure there are rare cases of people trading cards, but coupled with other metrics (don't only use this, since network cards can be changed), it's still possible.

您将如何获得它?

public static byte[] getMACAddress() throws SocketException, UnknownHostException {
    InetAddress address = InetAddress.getLocalHost();
    NetworkInterface networkInterface = NetworkInterface.getByInetAddress(address);

    return networkInterface.getHardwareAddress();
}

如果要使用String表示形式,请执行此操作

If you want a String representation, do this

for (int byteIndex = 0; byteIndex < macAddress.length; byteIndex++) {
    System.out.format("%02X%s", macAddress[byteIndex], (byteIndex < macAddress.length - 1) ? "-" : "");
}

(感谢 http://www.kodejava.org/examples/250.html)

注意:如评论中所述,可以欺骗Mac地址.但是您谈论的只是一小部分人,除非您将其用于反盗版,否则它的独特性就足够了.

Note: As mentioned in the comments, Mac addresses can be spoofed. But your talking about a small part of the population doing this, and unless your using this for anti-piracy stuff, its unique enough.

这篇关于生成特定计算机唯一的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆