你可以从 UUID 中提取什么样的数据? [英] What kind of data can you extract from a UUID?

查看:37
本文介绍了你可以从 UUID 中提取什么样的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以轻松提取 uuid 版本号.有没有可靠的方法来提取时间戳、MAC 地址等信息?

I know that we could easily extract the uuid version number. Is there a reliable way to extract information like timestamp, MAC address?

谢谢!

推荐答案

符合标准的 UUID 可能是几个变体之一,它看起来像这样:

A standard-conforming UUID may be one of several variants, it looks like this:

AAAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF

DDDD 部分的第一个(十六进制)数字决定了变体.

The first (hex)digit of the DDDD part determines the variant.

如果它是 8,9,A,B 之一,则符合当前规范(0-7为向下兼容保留,C、D为微软保留,E、F保留以备将来使用)

If it is one of 8,9,A,B it is conforming to the current spec (0-7 are reserved for backward compatibility, C,D are reserved for Microsoft, and E,F are reserved for future use)

如果它符合当前规范,请检查决定 UUID 版本的 CCCC 部分的第一个数字:

If it conforms to the current spec, check the first digit of the CCCC part which determines the UUID version:

  1. 基于时间的唯一或随机主机标识符 (MAC)
  2. DCE 安全版本(带有 POSIX UID)
  3. 基于名称(MD5 哈希)
  4. 随机
  5. 基于名称(SHA-1 哈希)

版本 4 只是随机选择.

Version 4 is simply randomly chosen.

版本 3 和 5 是通过散列和丢弃一些位生成的,这意味着您基本上没有机会从中恢复任何信息.有关如何构建它的详细信息可以在 RFC4122UUID 生成器网页.

Version 3 and 5 are generated by hashing and throwing away some bits which means you have basically no chance in recovering any information from it. Details on how to build it can be found in RFC4122 or at the UUID Generator webpage.

我找不到任何版本 2 UUID,所以我没有检查如何提取数据.

I could not find any version 2 UUIDs so I didn't check how to extract the data.

版本 1 是根据时间戳和当前主机 MAC 地址生成的.(如果您设置 MAC 地址的广播/多播"位,该标准还允许使用随机地址.)

Version 1 is generated from a time-stamp and current host MAC address. (The standard also allows to use a random address instead if you set the "broadcast/multicast" bit of the MAC address.)

以下 perl 片段从版本 1 uuid 解析 MAC 地址和时间:

The following perl snipped parses the MAC address and Time from a version 1 uuid:

my $uuid="AAAAAAAA-BBBB-CCCC-DDDD-FFFFFFFFFFFF";
$uuid=~tr/-//d;
my $time_low=hex substr($uuid,2* 0,2*4);
my $time_mid=hex substr($uuid,2* 4,2*2);
my $version =hex substr($uuid,2* 6,1);
my $time_hi =hex substr($uuid,2* 6+1,2*2-1);

my $time=($time_hi*(2**16)+$time_mid)*(2**32)+$time_low;
my $epoc=int($time /10000000) - 12219292800;
my $nano=$time-int($time/10000000)*10000000;

my $clk_hi  =hex substr($uuid,2* 8,2*1);
my $clk_lo  =hex substr($uuid,2* 9,2*1);
my $node    =substr($uuid,2*10,2*6);

$node=~/^(..)(..)(..)(..)(..)(..)$/ || die;
$node="$1:$2:$3:$4:$5:$6";

print "time: ",scalar localtime $epoc," +",$nano/10000,"ms\n";
print "clock id: ",$clk_hi*256+$clk_lo,"\n";
print "Mac: $node\n";

my $byte=hex $1;
if(hex($1)&1){
    print "broadcast/multicast bit set.\n";
};

最后但并非最不重要的是,有几个分配的 UUID,例如用于 GPT 分区.

And last but not least, there are several assigned UUIDs, for example for GPT partitions.

这篇关于你可以从 UUID 中提取什么样的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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