Coder Social home page Coder Social logo

as-you-like / deviceid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matthewking/deviceid

0.0 1.0 0.0 124 KB

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

License: MIT License

PowerShell 0.23% C# 99.68% Batchfile 0.09%

deviceid's Introduction

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.
  • AddOSInstallationID() adds the OS installation ID.
  • AddFileToken(path) adds a token stored at the specified path to the device ID.
  • AddRegistryValue() adds a value from the registry.
  • 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").

Dealing with MAC Address randomization and virtual network adapters

Non physical network adapters like VPN connections tend not to have fixed MAC addresses. For wireless (802.11 based) adapters hardware (MAC) address randomization is frequently applied to avoid tracking with many modern operating systems support this out of the box. This makes wireless network adapters bad candidates for device identification.

Use AddMacAddress(true, true) to exclude both virtual and wireless network adapters.

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.

Cross-platform support

The following cross-platform support is available:

Component Windows Linux OSX
User name Yes Yes Yes
Machine name Yes Yes Yes
OS version Yes Yes Yes
Processor ID Yes Yes No
MAC address Yes Yes Yes
Motherboard serial number Yes Yes No
System drive serial number Yes Yes Yes
System UUID Yes Yes No
OS installation ID Yes Yes Yes
Registry value Yes No No
File token Yes Yes Yes

Installation

Just grab it from NuGet

PM> Install-Package DeviceId
$ dotnet add package DeviceId

Strong naming

From version 5 onwards, the assemblies in this package are strong named for the convenience of those users who require strong naming. Please note, however, that the key files are checked in to this repository. This means that anyone can compile their own version and strong name it with the original keys. This is a common practice with open source projects, but it does mean that you shouldn't use the strong name as a guarantee of security or identity.

License and copyright

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

deviceid's People

Contributors

matthewking avatar cakkermans avatar phrohdoh avatar klyse avatar twistie avatar zaczero avatar progdogusmc avatar shshzi avatar techtim avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.