8000 GitHub - yuyu2you/DeviceId: A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.

License

Notifications You must be signed in to change notification settings

yuyu2you/DeviceId

 
 

Repository files navigation

DeviceId

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.

Quickstart

Building a device identifier

Use the DeviceIdBuilder class to build up a device ID.

string deviceId = new DeviceIdBuilder()
    .AddMachineName()
    .AddProcessorId()
    .AddMotherboardSerialNumber()
    .AddSystemDriveSerialNumber()
    .ToString();

What can you include in a device identifier

The following extension methods are available out of the box to suit some common use cases:

  • AddUserName() adds the current user's username to the device ID.
  • AddMachineName() adds the machine name to the device ID.
  • AddOSVersion() adds the current OS version (as returned by Environment.OSVersion) to the device ID.
  • AddMacAddress() adds the MAC address to the device ID.
  • AddProcessorId() adds the processor ID to the device ID.
  • AddMotherboardSerialNumber() adds the motherboard serial number to the device ID.
  • AddSystemDriveSerialNumber() adds the system drive's serial number to the device ID.
  • AddSystemUUID() adds the system UUID to the device ID.
  • AddFileToken(path) adds a token stored at the specified path to the device ID.
  • AddComponent(component) adds a custom component (see below) to the device ID.

Custom components can be built by implementing IDeviceIdComponent. There is also a simple DeviceIdComponent class that allows you to specify an arbitrary component value to use, and a WmiDeviceIdComponent class that uses a specified WMI property (example: new WmiDeviceIdComponent("MACAddress", "Win32_NetworkAdapterConfiguration", "MACAddress").

Controlling how the device identifier is formatted

Use the UseFormatter method to set the formatter.

string deviceId = new DeviceIdBuilder()
    .AddProcessorId()
    .AddMotherboardSerialNumber()
    .UseFormatter(new HashDeviceIdFormatter(() => SHA256.Create(), new Base64UrlByteArrayEncoder()))
    .ToString();

You can use one of the out-of-the-box implementations of IDeviceIdFormatter in the DeviceId.Formatters namespace, or you can create your own.

  • StringDeviceIdFormatter - Formats the device ID as a string containing each component ID, using any desired component encoding.
  • HashDeviceIdFormatter - Formats the device ID as a hash string, using any desired hash algorithm and byte array encoding.
  • XmlDeviceIdFormatter - Formats the device ID as an XML document, using any desired component encoding.

There are a number of encoders that can be used customize the formatter. These implement IDeviceIdComponentEncoder and IByteArrayEncoder and are found in the DeviceId.Encoders namespace.

Installation

Just grab it from NuGet

PM> Install-Package DeviceId
$ dotnet add package DeviceId

License and copyright

Copyright Matthew King 2015-2019. Distributed under the MIT License. Refer to license.txt for more information.

About

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.

Resources

License

Stars

Watchers

Forks

Packages

N 3164 o packages published

Languages

  • C# 99.4%
  • Other 0.6%
0