生成特定计算机唯一的ID

编程入门 行业动态 更新时间:2024-10-25 03:17:42
本文介绍了生成特定计算机唯一的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) ? "-" : ""); }

(感谢 www.kodejava/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

本文发布于:2023-11-11 10:27:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计算机   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!