虚拟机上的重复 GUID

发布于 11-02 14:43 字数 734 浏览 5 评论 0原文

在 VMWare 内恢复快照时,我已成功使用一个简单的 C#.NET 临时程序成功重现了相同的 GUID(是的,您没有看错)。客户端虚拟机是Windows Server 2008 R2 64位。我尝试过 Windows XP 和 Windows 7 64 位客户端,但没有成功。我使用的VMWare版本是6.5.3 build-185404。我所做的就是恢复到以前的快照,将临时程序复制到虚拟机,然后运行它。

对于那些不相信的人来说,有一些证据(我不怪你): https://i.sstatic .net/z3esp.png

这是临时程序的代码:

using System;
using System.Globalization;

namespace DuplicateGuid
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0} {1}", Guid.NewGuid(), DateTime.Now.Ticks));

            Console.ReadKey();
        }
    }
}

考虑到滴答数不同,任何人都可以阐明这是如何实现的吗?

I've managed to successfully reproduce the same GUID (yes, you read that correctly) using a simple C#.NET scratch program when reverting snapshots inside VMWare. The client virtual machine is Windows Server 2008 R2 64-bit. I've tried Windows XP and Windows 7 64-bit clients with unsuccessful results. The version of VMWare I'm using is 6.5.3 build-185404. All I do is revert to a previous snapshot, copy the scratch program over to the virtual machine, and then run it.

Some evidence for those that aren't convinced (I don't blame you): https://i.sstatic.net/z3esp.png

Here's the code for the scratch program:

using System;
using System.Globalization;

namespace DuplicateGuid
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0} {1}", Guid.NewGuid(), DateTime.Now.Ticks));

            Console.ReadKey();
        }
    }
}

Could anyone shed some light on how this is possible given that the tick count is different?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三五鸿雁2024-11-09 14:43:30

能否请您发布 GUID 之一。形象好像被破坏了。

请参阅 http://en.wikipedia.org/wiki/Globally_unique_identifier 特别是“算法”。您在 Windows 2008 R2 x64 下使用的平台可能正在使用版本 4 GUID。在这种情况下,GUID 是使用伪随机数据生成的。由于 CPU 处于相同的状态,因为您将其从我假设的内存快照(正确吗?)而不是断电快照恢复回来,因此您将从伪随机生成器中获得重复的数字。

操作系统在启动时初始化一个伪随机种子,然后从列表中顺序提取数字以形成随机数,这是相当常见的。这种情况发生在 Linux 世界中,您很可能正在观察到相同的行为。因为数字序列尚未重新初始化,并且您正在恢复到内存图像,所以您将得到相同的数字。

使用 VS 2010 中的 GUID 生成器,我在 Windows 7 上获得了 V4 GUID。

要解决此问题,我首先尝试应用可能解决此问题的 Windows 安全修复程序。问题很可能出在 Guid.NewGuid 方法中调用的 ole32.dll 中,并且可能较新的版本重新设置了伪随机数,因为您在较新的 Windows 版本上没有得到此值。

否则,要在当前平台上解决此问题,您可以:

  1. 根据 OSF 规范中指定的 MAC 和时间数据生成您自己的 GUID。

  2. 尝试在 NewGuid 调用之前调用 new Random() 。这可能是一个不太可能的事情,但很容易测试。

  3. 不要从内存映像恢复。

希望这有帮助。毫无疑问,您不是第一个遇到此问题的人,这就是为什么较新的平台可能会恢复到以前使用 MAC 和时间数据的方法。

Can please you post one of the GUIDs. The image seems to be broken.

See http://en.wikipedia.org/wiki/Globally_unique_identifier specifically "Algorithm". It is likely the platform you are using under Windows 2008 R2 x64 is using version 4 GUIDs. In this case the GUID is generated using pseudo random data. As the CPU is in the same state because you are reverting it back from what I assume is a memory snapshot (correct?) and not a powered off snapshot you are getting duplicate numbers from the pseudo random generator.

It is reasonably common for the operating system to initialise a pseudo random seed once at startup sequentially pulling numbers from the list to make the appearance of a random number. This happens in the Linux world and it is likely that you are observing the same behaviour. Because the sequence of numbers has not been reinitialised and you are reverting back to a memory image you are getting the same numbers.

Using GUID Generator from VS 2010 I got a V4 GUID on Windows 7.

To fix this issue I would first try to apply Windows security fixes which may fix the issue. The problem mostly likely lies in ole32.dll which is called in the Guid.NewGuid method and possibly newer versions reseed the pseudo random number as you didn't get this on newer Windows versions.

Otherwise to work around this issue on the current platform you could:

  1. Generate your own GUID from MAC and time data as specified in OSF specification.

  2. Try to call new Random() prior to your NewGuid call. This probably would be a long shot, but easy to test.

  3. Don't revert from a memory image.

Hope this helps. No doubt you are not the first to have this problem which is why the newer platforms probably reverted to the previous method of using MAC and time data.

贩梦商人2024-11-09 14:43:30

GUID 不保证唯一,但概率极小。也许你很幸运。 :)

GUIDs are not guaranteed to be unique, but the probability is extremely small. Maybe you got (un)lucky. :)

じее2024-11-09 14:43:30

我不希望在没有物理网卡的机器上生成的 GUID 具有任何唯一性。虚拟卡的 MAC 地址实际上可以保证在同一虚拟机的克隆上重复。

I wouldn't expect ANY uniqueness from GUIDs generated on a machine without a physical network card. The MAC address of a virtual card is practically guaranteed to repeat on clones of the same VM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文