1

I am trying to generate a unique GUID for a Windows Web Application I am making in C#. Does anyone have a suggestion on how I could do this? I need a unique machine GUID not depending on system OS (Mac, Windows, Linux). Where would I start?

Darren
  • 10,631
  • 8
  • 42
  • 64
  • 1
    What is a "machine GUID?" Why would [`System.Guid.NewGuid()`](http://msdn.microsoft.com/en-us/library/system.guid.newguid.aspx) not work? – cdhowie Jul 25 '12 at 03:58
  • this one might help you, http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript – ABH Jul 25 '12 at 04:02
  • Could you clarify what you mean by a "unique machine GUID". A GUID (Globally unique identifier) is a 16-byte number that is generated based on enough entropy for it to be very likely to be unique. There are a number of ways these 16-bytes (126 bits) can be represented, although this isn't specific to operating system and any of these formats will convey the same value relative to each other. – Sam Greenhalgh Jul 25 '12 at 04:07
  • Hello all, I need a GUID that I can reference a computer with, all the time. Guid.NewGuid() always gives me a random Guid. I want to use the Guid to identify the system. – Darren Jul 25 '12 at 15:54

3 Answers3

4

A GUID is, by definition, unique. You can use the following to generate a new GUID:

var guid = Guid.NewGuid();
Teppic
  • 2,506
  • 20
  • 26
1

I am taking the system's network Id, this is what I did:

Guid macAddressGuid;
NetworkInterface[] networkInterface = NetworkInterface.GetAllNetworkInterfaces();
string id = networkInterface.FirstOrDefault().Id;

Guid.TryParse(id, out macAddressGuid);

return macAddressGuid;

Some of you might be saying this can be spoofed and it can, however in the type of application I am building this is not a big security concern because of the nature of the application. A user can register if they wish to have better security.

Thank you all for your input, I really appreciate it.

Darren
  • 10,631
  • 8
  • 42
  • 64
0

There is a GUID created by windows setup and stored in the windows registry. But you can't rely this being unique. For other platforms there may or may not be a similar thing depending on OS. You'll be ending up creating and administering GUIDs for the systems yourself.

fan711
  • 716
  • 3
  • 13