Skip to content

About

Simple .NET library capable of tracking users across re-installs and hardware components swapping, and even entirely new computer using the neighborhood's network endpoints.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Repository files navigation

HardwareIds.NET

Fingerprint a Windows machine straight from the Windows APIs, with no WMI and no dependencies.

NuGet version NuGet downloads CI Publish License Targets

HardwareIds.NET enumerates every hardware component of the computer it runs on and collects the identifiers that survive re-installs and component swaps: serial numbers, MAC addresses, firmware and partition table GUIDs, EDID blocks, SMBIOS data, the Windows installation identifiers, and optionally the Wi-Fi networks and LAN devices around the machine, so a user can be recognised even on an entirely new computer sitting in the same place.

Highlights

  • Direct. Everything is read from the Windows APIs: the SMBIOS table, storage and NDIS IOCTLs, the PnP configuration manager, the registry, the print spooler, the display configuration API, the battery and Bluetooth APIs, WlanAPI, TPM Base Services and CNG. No WMI, no winmgmt service, no WmiPrvSE host.
  • Fast. A scan takes about 10 ms, plus a few hundred for the TPM's public keys and certificates (seconds on some firmware, or while other applications use the TPM), which ScanTpmKeys = false leaves out.
  • Dependency-free. No third-party packages. Only System.Text.Json on .NET Framework, which is part of .NET 10.
  • Works without elevation. Restricted TPM fields and machine keys remain unavailable; network signatures require elevation.
  • WMI-compatible values. The historical fields hold the exact strings WMI reports, so identifiers collected by earlier versions keep matching.
  • Serializable. The result is a plain object with System.Text.Json attributes; serialize it and store it as is. Every snapshot carries the library_version that produced it, and a JSON schema describes the output, so other applications can validate the snapshots they receive. Hwid.ToJson() and the source-generated HwidJsonContext write the same JSON without reflection, for trimmed and Native AOT applications.
  • Tested. 270+ unit and integration tests, the latter checking every collector against WMI as an independent oracle.
  • C and C++ too. HardwareIds.Cpp is a native port that writes the very same JSON, byte for byte.

What is collected

Section Source Identifiers
disks Storage IOCTLs, NVMe / ATA identify, SCSI VPD page 0x83, PnP Model, descriptor serial, NVMe serial / EUI-64 / NGUID / FGUID, ATA serial / WWN, VPD identifiers, Windows DUID, firmware, partition table GUID, instance path
volumes Volume management API Volume GUID path, drive letter, NTFS/FAT serial
network_adapters GetIfTable2, registry, PnP Current and permanent MAC, interface GUID, driver service, install date, instance path
bluetooth_radios Bluetooth API Radio address, name, manufacturer, class of device
baseboards, motherboards, chassis, bios_firmwares, smbios_tables SMBIOS (GetSystemFirmwareTable) Board serial, system UUID, chassis serial and asset tag, BIOS version, hash of the whole table
processors SMBIOS, CPUID, registry Model, ProcessorId, socket, cores and threads
memory_sticks SMBIOS Manufacturer, part number, serial, capacity, speed, slot
batteries Battery IOCTLs Serial, unique ID, chemistry, capacities, manufacture date
monitors EDID (PnP registry) Manufacturer, product code, serial, name, EDID hash, manufacture week and year, instance path
video_controllers PnP, display configuration API Name, driver version and date, current mode, instance path
printers Print spooler Name, port, location, resolution
users NetUserEnum Local accounts with their SIDs
operating_systems Registry, branding API Edition, version, product ID, install date and time, machine GUID, hardware profile GUID, machine SID
wifis (optional) WlanAPI scan SSID, BSSID, signal, channel, band
routers (optional) Neighbour cache, ARP sweep Gateways with their MAC, DNS and DHCP servers, every device on the LAN
network_signatures Registry (elevated only) Networks the machine connected to, with their gateway MAC
tpms TBS, TPM2_GetCapability, Platform Crypto Provider, certificate stores TPM version, manufacturer, firmware, specification, flags, lockout state, raw properties, algorithms, PCR banks, public EK/SRK and persisted keys, endorsement and associated certificates

Installation

dotnet add package HardwareIds.NET
PM> Install-Package HardwareIds.NET

Requirements: Windows, and .NET 10 or .NET Framework 4.8.

Usage

using HardwareIds.NET;

// Hardware only, including the TPM's available public key material.
var Hwid = HardwareIds.GetHwid();

Console.WriteLine(Hwid.Motherboard?.UUID);
Console.WriteLine(Hwid.Disk?.NvmeSerial ?? Hwid.Disk?.AtaSerial ?? Hwid.Disk?.SerialNumber);
Console.WriteLine(Hwid.OperatingSystem?.MachineGuid);
// With the network probes: a few seconds, bound by the Wi-Fi scan.
var Hwid = await HardwareIds.GetHwidAsync(new HardwareIdsConfig
{
    ScanNeighborEndpoints = true,                                 // Wi-Fi networks around the computer
    DurationOfNetworkScan = TimeSpan.FromSeconds(3),              // how long to wait for the Wi-Fi scan
    ScanLocalNetworkDevices = true,                               // devices on the LAN, with their MAC addresses
    DurationOfLocalNetworkScan = TimeSpan.FromSeconds(1),         // how long to wait for the devices to answer
}, cancellationToken);

foreach (var Wifi in Hwid.Wifis.OrderByDescending(T => T.Strength))
    Console.WriteLine($"{Wifi.Ssid,-32} {Wifi.Bssid}  {Wifi.Strength} dBm  channel {Wifi.Channel}");

foreach (var Device in Hwid.Router?.NetworkDevices ?? [])
    Console.WriteLine($"{Device.Ip,-16} {Device.MacAddress}");
// The TPM's public keys and certificates take most of the time of a scan: a few hundred milliseconds, against about
// 10 ms for everything else. Leave them out, or the whole TPM, when you do not need them.
var Hwid = HardwareIds.GetHwid(new HardwareIdsConfig { ScanTpmKeys = false });   // or ScanTpm = false
// The result serializes as is, with stable snake_case property names; its last property, library_version, is the
// version of the library that produced it ("2.4.0", also HardwareIds.Version).
var Json = JsonSerializer.Serialize(Hwid);

// The very same JSON without reflection, for trimmed and Native AOT applications.
Json = Hwid.ToJson();   // or JsonSerializer.Serialize(Hwid, HwidJsonContext.Default.Hwid)

Every section is a list, and each has a convenience getter for its first entry (Hwid.Disk, Hwid.Processor, Hwid.OperatingSystem, Hwid.Tpm, ...). Collectors never throw. Missing components yield empty lists; TPM queries retain partial results and expose individual failures in Tpm.Errors.

GetHwidAsync runs the collectors on the thread pool, so awaiting it never blocks the calling thread (a UI thread, for example); GetHwid runs them on the caller's. A deserialized snapshot keeps the LibraryVersion it was written with, which is null for the snapshots of versions before 2.4.0.

TPM information

var Tpm = HardwareIds.GetHwid().Tpm;

if (Tpm != null)
{
    Console.WriteLine($"TPM {Tpm.Version}: {Tpm.Manufacturer}");

    foreach (var Key in Tpm.Keys)
        Console.WriteLine($"{Key.Kind} / {Key.Scope} / {Key.Name}: {Key.PublicKeySha256}");

    foreach (var Certificate in Tpm.Certificates)
        Console.WriteLine($"{Certificate.Source}: {Certificate.Subject} ({Certificate.Sha256})");

    foreach (var Error in Tpm.Errors)
        Console.WriteLine($"{Error.Operation}: {Error.Source} 0x{Error.Code:X8}");
}
  • Keys includes the default, RSA and ECC endorsement public keys, the storage-root public key, and accessible persisted keys from the Microsoft Platform Crypto Provider in the current-user and local-machine scopes. Identity keys (AIKs) can be identified by bit 0x8 of TpmUsage. Enumeration follows the caller's access rights.
  • PublicKeyBlob is Base64-encoded BCRYPT public-key data (RSA, ECC or full ECC); PublicKeySha256 hashes those exact bytes, not SubjectPublicKeyInfo or the certificate. Length is in bits, or null if the curve size is unknown. Malformed public blobs are rejected. Private keys and authorization secrets are not read.
  • Certificates contains available PCP endorsement certificate stores, including the NV-backed stores. Source identifies each store, so the same certificate can occur under several sources. Each entry includes complete DER in Base64, SHA-256, subject, issuer, serial number, UTC validity and algorithm OIDs. Keys[i].Certificates also includes certificates returned by the key property or matched by provider/container in the Personal (My) stores.
  • TPM 2.0 exposes fixed and variable properties, specification and firmware words, supported algorithm IDs, and PCR selection bitmaps. A set bit in PcrBanks[i].Selection selects that PCR (least-significant bit first within each byte); PCR digest values are not collected. Firmware words retain the vendor's encoding. TPM 1.2 receives TBS and available PCP information; TPM 2.0-only fields stay null or empty.
  • Reads use TBS and silent CNG enumeration. The collector does not create, clear, provision or modify keys, prompt for authorization, download certificates, or validate certificate trust. TPM access is serialized within each process, with bounded retries for transient read failures.
  • A missing TPM yields Tpms = []. Unsupported properties, denied access and failed queries leave their fields null or lists empty, with raw codes in Errors (TBS, TPM, NCrypt or Win32). A null boolean means unknown. Each PCP certificate store and persisted-key scope is limited to 1,024 entries; truncation is reported in Errors. Cancellation is checked between queries and enumeration steps; an in-flight Windows API call finishes first.

A disk, for example

{
  "id": 1,
  "interface": "SCSI",
  "model": "Samsung SSD 980 PRO 2TB",
  "serial_number": "0025_384A_471F_58A7.",
  "capacity": "1863 GB",
  "partitions": 3,
  "firmware": "5B2QGXA7",
  "world_wide_name": "0025384A471F58A7",
  "disk_guid": "95002274-501c-4590-8f6c-6b45c75a3a0c",
  "nvme_serial": "S69ENC5C753184B",
  "nvme_eui64": "0025384A471F58A7",
  "vpd_scsi_name": "eui.0025384A471F58A7",
  "duid": "3f1c…"
}

A drive legitimately reports different serial numbers depending on the layer asked. serial_number is the value WMI reports (for NVMe drives, Windows derives it from the EUI-64), while nvme_serial or ata_serial is the serial printed on the label. All of them are kept, each in its own field.

JSON schema

hwid.schema.json is a JSON Schema (draft-07) of the snapshot, for applications that receive snapshots and must validate them. It matches what both the .NET library (serialized with the default JsonSerializerOptions, or Hwid.ToJson()) and the C++ port write. Each release has a copy of the file attached.

The schema is strict, and versioned with the library:

  • Every property is required, and unknown properties are rejected, so a snapshot only validates against the schema of the version that produced it. That version is in the snapshot, library_version ("2.4.0"): keep the schema of every release you accept, read the property first and validate with the matching schema. Snapshots from versions before 2.4.0 have no library_version.
  • The $id of each schema is the address of the file in the tag of its release, so a validator that caches schemas by identifier can hold several versions at once. The schemas of 2.3.0 and 2.4.0 share theirs, and the same definitions.
  • Strings the library may leave unset are string or null. Numbers are bounded to their 32-bit range.
  • Values whose format the library controls are checked: dates, the system UUID, MAC addresses (upper-case hexadecimal pairs separated by colons), SHA-256 hashes (lower-case hexadecimal), Base64 data and the TPM enumerations. Free-form strings such as serial numbers and names are not constrained.
  • The Wi-Fi measurements keep their historical PascalCase names (Strength, Channel, Frequency, Band, Quality). A custom PropertyNamingPolicy changes them, so serialize with the default options for the schema to apply.

Validating a snapshot in PHP (Laravel, for example) with opis/json-schema:

use Opis\JsonSchema\Validator;

$Snapshot = json_decode($request->getContent());   // decode to objects, not associative arrays
$Version = $Snapshot->library_version ?? '2.3.0';  // absent before 2.4.0; each release attaches hwid-<version>.schema.json

if (!preg_match('/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/', $Version) || !is_file(resource_path("schemas/hwid-$Version.schema.json"))) {
    abort(422, 'Unsupported hardware snapshot version.');
}

$Result = (new Validator())->validate($Snapshot, file_get_contents(resource_path("schemas/hwid-$Version.schema.json")));

if (!$Result->isValid()) {
    abort(422, 'Invalid hardware snapshot.');
}

The tests validate scans of the machine and synthetic snapshots against the schema, so a change to the serialized properties fails until the schema follows.

C and C++

HardwareIds.Cpp is a port of the library to C++20 for native programs. It runs the same collectors with the same rules and serializes the result to the JSON JsonSerializer.Serialize(Hwid) produces, byte for byte, so a snapshot taken by a native program can be compared directly with one taken from .NET. CI checks this on every push by diffing the output of both libraries on the runner. It needs MSVC and CMake 3.21 or later, and nothing else.

Adding it to a CMake project

include(FetchContent)
FetchContent_Declare(HardwareIds
    GIT_REPOSITORY https://github.com/BerkanYildiz/HardwareIds.NET.git
    GIT_TAG        master                # or a release tag
    SOURCE_SUBDIR  HardwareIds.Cpp)
FetchContent_MakeAvailable(HardwareIds)

target_link_libraries(MyApp PRIVATE HardwareIds::HardwareIds)   # static library: C++ and C API

add_subdirectory(path/to/HardwareIds.Cpp) works the same way. Each release also attaches HardwareIds.Cpp-<version>-win-x64.zip, a prebuilt install tree for find_package(HardwareIds CONFIG REQUIRED): it holds HardwareIds::Shared (HardwareIds.dll, the C API, usable from any configuration and any compiler) and HardwareIds::HardwareIds (the static library, built in Release with /MD).

C++

#include <HardwareIds/HardwareIds.hpp>

// Hardware only, including the TPM's available public key material.
auto Hwid = HardwareIds::GetHwid();

std::string Json = HardwareIds::ToJson(Hwid);                                     // JsonSerializer.Serialize(Hwid)
std::string Pretty = HardwareIds::ToJson(Hwid, HardwareIds::JsonFormat::Indented); // ... with WriteIndented = true
std::wstring Version = HardwareIds::Version();                                    // L"2.4.0", the Hwid.LibraryVersion of every snapshot

for (const auto& Disk : Hwid.Disks)
    std::wcout << Disk.Model.value_or(L"?") << L"  " << Disk.NvmeSerial.value_or(Disk.SerialNumber.value_or(L"")) << L'\n';
// With the network probes. Requesting a stop ends the scans early, like the .NET cancellation token.
HardwareIds::HardwareIdsConfig Config;
Config.ScanNeighborEndpoints = true;
Config.DurationOfNetworkScan = std::chrono::seconds(3);
Config.ScanLocalNetworkDevices = true;
Config.ScanTpmKeys = false;                                  // skip the TPM's keys and certificates, the slowest part (or ScanTpm)

std::stop_source Stop;
auto Hwid = HardwareIds::GetHwid(Config, Stop.get_token());

The structures mirror the .NET ones: the same sections and fields, strings as std::wstring, and missing values as std::nullopt (JSON null).

C

#include <HardwareIds/HardwareIds.h>

HardwareIds_Options Options = { 0 };            /* or pass NULL: hardware only, compact JSON */
Options.ScanLocalNetworkDevices = 1;

char* Json = HardwareIds_GetSnapshotJson(&Options);

if (Json != NULL)
{
    puts(Json);
    HardwareIds_Free(Json);
}

HardwareIds_GetSnapshotJsonEx(&Options, HARDWAREIDS_SKIP_TPM_KEYS) takes the same options and flags that leave the TPM's keys and certificates (or, with HARDWAREIDS_SKIP_TPM, the whole TPM) out of the snapshot.

Link against HardwareIds.lib and ship HardwareIds.dll next to the program, or link the static library and define HARDWAREIDS_STATIC (the CMake target defines it for you).

Snapshot tool

HardwareIdsSnapshot prints a snapshot from the command line:

HardwareIdsSnapshot --indented --wifi=3 --lan --output snapshot.json

--no-tpm-keys and --no-tpm leave the TPM's keys and certificates, or the whole TPM, out of it.

Notes on the identifiers

  • ProcessorId is the CPUID signature the firmware records in SMBIOS, as WMI reports it: identical for every CPU of the same model and stepping, not unique per chip, and all zeros under some hypervisors (Hyper-V, Azure).
  • network_signatures needs an elevated process; it is empty otherwise.
  • routers lists only devices inside the subnets of the interface and never devices answering with a gateway's MAC, which filters out the proxy-ARP artefacts of statically routed hosts.
  • The Windows product key is deliberately not collected.

Building and testing

dotnet build
dotnet test

The test project runs on both target frameworks. Unit tests exercise the SMBIOS, EDID, NVMe, ATA, SCSI and TPM parsers on synthetic data; integration tests run every collector on the local machine and compare the results with WMI. Tests that need hardware or privileges the machine lacks (Wi-Fi, a battery, a Bluetooth radio, monitor EDID, elevation) are skipped, not failed.

The C++ library has its own tests, and a script that checks both libraries print the same snapshot. Boot time and volatile TPM state are masked during live comparisons; key material, certificates and fixed TPM capabilities are compared:

cmake -S HardwareIds.Cpp -B HardwareIds.Cpp/build
cmake --build HardwareIds.Cpp/build --config Release
ctest --test-dir HardwareIds.Cpp/build --build-config Release
./.github/scripts/parity.ps1 -Snapshot HardwareIds.Cpp/build/Release/HardwareIdsSnapshot.exe

Releasing

  1. Write the new version in VERSION, the single source of the version of both libraries, and in the $id of hwid.schema.json (a test fails until they agree).
  2. Describe the release in CHANGELOG.md, under a dated ## [2.4.0] - 2026-11-03 heading.
  3. Commit, then push a tag carrying the same version:
git tag v2.4.0
git push origin v2.4.0

The Publish workflow refuses a tag whose version differs from VERSION or has no dated CHANGELOG.md section. It builds and tests the solution, packs the library with the changelog section as its release notes, pushes it to NuGet.org and GitHub Packages, and attaches the packages to a GitHub release whose body is that section followed by the generated notes, along with the zip of the C++ library and hwid.schema.json. A tag with a pre-release suffix (v2.4.0-beta.1) produces a pre-release.

Every build compares the public API of the package with the release named by PackageValidationBaselineVersion in the project file, and fails when a member was removed or changed. Once a release is on NuGet.org, raise that version to it. The package carries a copy of this file made for NuGet.org: a Markdown title in place of the header, and links pointing to the files of the release.

No secret is involved: NuGet.org is reached through Trusted Publishing, which exchanges the workflow's OIDC token for a one-hour API key, and GitHub Packages uses the built-in token. The nuget.org account owning the package needs one Trusted Publishing policy (profile menu, Trusted Publishing):

Field Value
Package Owner the nuget.org profile that owns HardwareIds.NET
CI/CD Provider GitHub Actions
Repository Owner BerkanYildiz
Repository HardwareIds.NET
Workflow File publish.yml
Environment leave empty
Scopes Push, new packages and package versions
Glob Patterns and Packages HardwareIds.NET

License

MIT. See LICENSE.

About

Simple .NET library capable of tracking users across re-installs and hardware components swapping, and even entirely new computer using the neighborhood's network endpoints.

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages