Giter Site home page Giter Site logo

node-machine-id's Introduction

Cross-platform unique machine (desktop) id discovery

Use cases

  • Software restrictions
  • Installation tracking

Features

  • Hardware independent
  • Unique within the OS installation
  • No elevated rights required
  • No external dependencies and does not require any native bindings
  • Cross-platform (OSx, Win, Linux)

How it works

Module based on OS native UUID/GUID which used for internal needs.

All others approaches requires elevated rights or much depends on hardware components, but this approach summarize the methods of selecting the most reliable unique identifier

  • Win32/64 uses key MachineGuid in registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography (can be changed by administrator but with unpredictable consequences)

It is generated during OS installation and won't change unless you make another OS updates or reinstall. Depending on the OS version it may contain the network adapter MAC address embedded (plus some other numbers, including random), or a pseudorandom number.

  • OSx uses IOPlatformUUID (the same Hardware UUID) ioreg -rd1 -c IOPlatformExpertDevice

Value from I/O Kit registry in IOPlatformExpertDevice class

The /var/lib/dbus/machine-id file contains the unique machine ID of the local system that is set during installation. The machine ID is a single newline-terminated, hexadecimal, 32-character, lowercase machine ID string. When decoded from hexadecimal, this corresponds with a 16-byte/128-bit string.

The machine ID is usually generated from a random source during system installation and stays constant for all subsequent boots. Optionally, for stateless systems, it is generated during runtime at early boot if it is found to be empty.

The machine ID does not change based on user configuration or when hardware is replaced.

Installation

npm install node-machine-id

Usage

Function: machineId(original)

  • original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false

Function: machineIdSync(original);

  • syncronous version of machineId
import {machineId, machineIdSync} from 'node-machine-id';

// Asyncronous call with async/await or Promise

async function getMachineId() {
    let id = await machineId();
    ...
}

machineId().then((id) => {
    ...
})

// Syncronous call

let id = machineIdSync()
// id = c24b0fe51856497eebb6a2bfcd120247aac0d6334d670bb92e09a00ce8169365
let id = machineIdSync(true)
// id = 98912984-c4e9-5ceb-8000-03882a0485e4

Caveats

  • Image-based environments have usually the same machine-id

As a workaround you can generate new machine-ids for each instance (or container) with dbus-uuidgen and changed them in the respective > files: /etc/machine-id and /var/lib/dbus/machine-id. Thanks @stefanhuber

node-machine-id's People

Contributors

akhudushin avatar automation-stack avatar bguiz avatar dependabot[bot] avatar enet4 avatar hojothum avatar hubdotcom avatar jahraphael avatar root-core avatar vutran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-machine-id's Issues

Error Starting

After installing node-machine-id (npm install node-machine-id)
After creating a "clean" project (typescript/angular2)

I got the following error:
ERROR in app/app.component.ts (2,40): Cannot find module 'node-machine-id'.)

ERROR in ./~/node-machine-id/dist/index.js
Module not found: Error: Can't resolve 'child_process' in '\machineID\node_modules\node-machine-id\dist'

---app.component.ts--
import { Component } from '@angular/core';
import {machineId, machineIdSync} from 'node-machine-id';

@component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = machineId();
}

Can this used for mobile browser too?

I need to log in my user based on this unique id. Does this help? Also does this work for mobile too? since users will use the website on mobile too.

Detecting Terminal Server

I'm using this module for licensing my electron app. It's worked great, but a user just pointed out that they can run unlimited copies of my app on a Remote Desktop. Hmmm! That's interesting...

I found this guide, but I'm not clear how this module could change to provide a level of detection/identification for terminal services, and thus how I'd change my licensing.

Just thought I'd put this out for discussion, in case there's something obvious I'm overlooking. Feel free to close this issue if it's off-topic.

vite how to use

It seems necessary to use webpack,What if we use vite packaging

NanoBSD: missing kenv "smbios.system.uuid" value

Hi!

I have a NanoBSD deployment (FreeBSD 11.2 based). This deployment is not SMBIOS-enabled which results in missing value for kenv variable "smbios.system.uuid".

My suggestion is to use "sysctl -n kern.hostuuid" (which is more widely-present IMHO) in FreeBSD systems with or instead of "kenv -q smbios.system.uuid" to cover more FreeBSD-based systems.

Results are the same:
$ sysctl -n kern.hostuuid
774b2382-fb5f-4cb2-966b-e2beae8c9d51
$ kenv -q smbios.system.uuid
774b2382-fb5f-4cb2-966b-e2beae8c9d51

So I suggest the following command to use:
kenv -q smbios.system.uuid || sysctl -n kern.hostuuid

How does it work?

I perused the code a bit, but got lost and/or distracted.

At a high level, how does this library work?

Arch linux support

There is no /var/lib/dbus/machine-id file in Arch linux by default, but /etc/machine-id still exists

ERROR: The system was unable to find the specified registry key or value.

this error popping up while I'm running " reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2" /f
in my cmd.

thing is I'm facing an error called " no such interface supported " whenever i am opening a particular app in my pc(win10) , so i was trying out this command as a fix , but it showed me this error.

any help regarding this ?
screenshot 212

Throw a error on intel mac 10.15.7 19H1824 Command failed

Error while obtaining machine id: 
Error: Command failed: ioreg -rd1 -c IOPlatformExpertDevice 
    at ChildProcess.exithandler (node:child_process:406:12) 
    at ChildProcess.emit (node:events:390:28) 
    at maybeClose (node:internal/child_process:1064:16) 
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28) 
    at Pipe.<anonymous> (node:net:687:12)

Can't resolve 'child_process'

On importing import {machineId, machineIdSync} from 'node-machine-id' in app component then getting this error. Any work around for the same.
ERROR in ./node_modules/node-machine-id/dist/index.js
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\farhan\Desktop\ Farhan\Projects\BFMC\BFMClient\node_modules\node-machine-id\dist'

Command Prompt flashes

On Windows, when implemented with an express.js server, the command prompt seems to flash appear whenever the function is called.

Is there anyway to workaround this?

d.ts

I would like to use this in Typescript 2.1, is there a type definition file for this?

Command failed: Registry editing has been disabled by your administrator.

I am having lots of errors on Windows (App not loading properly) and after some digging, the error happens to be from this library that relies on running regedit in the background.

If I run this code:

const machine = require('node-machine-id');

machine.machineId().then((id) => {
    console.log(id);
}).catch((err) => {
    console.log(err);
})

I get the following error on Windows:

C:\Users\j\machineId> node index.js
Error: Error while obtaining machine id: Error: Command failed: %windir%\System32\REG.exe QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid
ERROR: Registry editing has been disabled by your administrator.

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:314:20)
    at Pipe.<anonymous> (net.js:676:12)
    at C:\Users\j\machineId\node_modules\node-machine-id\dist\index.js:1:7964
    at ChildProcess.exithandler (child_process.js:315:5)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:314:20)
    at Pipe.<anonymous> (net.js:676:12)

The error hints that this user does not have admin privileges to run regedit, thus is unable to obtain the unique machine ID. Is there a way of resolving this issue?

Also, thank you for building this library!

OS X updates query

Hi,
Am I to understand from this information..

It is generated during OS installation and won't change unless you make another OS updates or reinstall.

..that the machine id would change if a user updates their OS X version (Yosemite to Sierra for example)?

If this is the case then it would be a problem for me. Can you clarify this?

Thanks, John

could not find machine-id file

I use node-machine-id in my electron app and one of users reported this bug:

Just installed cerebro on Arch Linux and this happened:

cat: /var/lib/dbus/machine-id: No such file or directory
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Command failed: cat /var/lib/dbus/machine-id
cat: /var/lib/dbus/machine-id: No such file or directory

    at checkExecSyncError (child_process.js:495:13)
    at execSync (child_process.js:535:13)
    at childProcess.(anonymous function) (ELECTRON_ASAR.js:685:22)
    at c (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:309:7107)
    at Object.<anonymous> (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:283:100)
    at __webpack_require__ (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:21:30)
    at Object.<anonymous> (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:159:20)
    at __webpack_require__ (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:21:30)
    at Object.<anonymous> (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:52:22)
    at __webpack_require__ (/tmp/.mount_wzwsP7/usr/bin/resources/app.asar/main.js:21:30)

I solved it by creating a sym link to the file that actually was located at /etc/machine-id instead of /var/lib/dbus/machine-id

Error: Error while obtaining machine id

Error: Error while obtaining machine id: Error: Command failed: %windir%\System32\REG.exe QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid
����: ϵͳ�Ҳ���ָ����ע������ֵ��

at ChildProcess.exithandler (child_process.js:312)
at ChildProcess.emit (events.js:315)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286)
at chunk-5ac52539.df366d92.js:1
at ChildProcess.exithandler (child_process.js:319)
at ChildProcess.emit (events.js:315)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286)

this error occurs when electron is packaged

Does this work in a browser?

I was using electron-machine-id and updated to this thinking it would work in chrome?

Does it still require electron or NW?

ERROR in ./node_modules/node-machine-id/dist/index.js
Module not found: Error: Can't resolve 'child_process' in 'f:\Github\electron-store\node_modules\node-machine-id\dist'
@ ./node_modules/node-machine-id/dist/index.js 1:82-106 1:18348-18372
@ ./src/js/helper.js
@ ./src/purchase-entry.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/purchase-entry.js

Double machine id got in linux machine

The machine id usually got only one like 12345, but now the double like 1234512345. Is that caused by cat command on two files?
cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null

Electron and windows

Someone has managed to use the node-machine-id within the Electron in Windows?
When we do the build, the software does not load, it is blank and does not display any error message.

async and await in example

I'm using ES6 on Windows and Electron. I've never used async or await, but I tried your example and I got javascript errors. Is there a better way of using it async?

Not working on fedora 25

Error: Command failed: cat /var/lib/dbus/machine-id
cat: /var/lib/dbus/machine-id: No such file or directory

After sudo ln -s /etc/machine-id /var/lib/dbus/machine-id works fine

Ghost cloned system

Image-based environments have usually the same machine-id

Does it mean that Ghost cloned system has same machine id?

Strange error on Mac

i get this error while using it with electron and react
TypeError: (0 , p.exec) is not a function
any ideas whats wrong?

import function not working

Hi!
I'm using your code, but I get this error

import {machineIdSync} from 'node-machine-id';

        ^^^^^^^^^^^^^
SyntaxError: The requested module 'node-machine-id' does not provide an export named 'machineIdSync'

In order to make it working, I import the module and then use default object to call exported function:

import ClientUtility from 'node-machine-id';
...
ClientUtility.machineIdSync({original: true})

My environment is node 13, so I'm using modules.
Is it possibile to import without default, or this is the right way to use it?
Thanks!

Same machine id on raspberry pi

I have an electron app with this library running on rasperry pi. Unfortunately, on every raspberry pi the same machine id is generated. This is caused be the fact that all raspberries are based on the same image.

As a workaround I generated new machine-ids for each rapberry with dbus-uuidgen and changed them in the respective files: /etc/machine-id and /var/lib/dbus/machine-id.

Can't resolve 'child_process' in ' \node_modules\node-machine-id\dist'

When I install the package and try to use it, I get this error :

ERROR in ./node_modules/node-machine-id/dist/index.js Module not found: Error: Can't resolve 'child_process' in 'C:\Users\xxx\Source\Repos\xxx\node_modules\node-machine-id\dist' @ ./node_modules/node-machine-id/dist/index.js 1:82-106

(Pic related)
image

ERROR: The system was unable to find the specified registry key or value.

When run application(32bit) in window 64bit, I meet this errror

ERROR: The system was unable to find the specified registry key or value.
{ Error: Command failed: REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptog
raphy /v MachineGuid
ERROR: The system was unable to find the specified registry key or value.

at checkExecSyncError (child_process.js:495:13)
at execSync (child_process.js:535:13)
at childProcess.(anonymous function) (ELECTRON_ASAR.js:685:22)
at Object.c [as machineIdSync] (XXX\

dist\win-ia32-unpacked\resources\app.asar\node_modules\node-machine-id\dist\inde
x.js:1:7226)

And I found this link: http://superuser.com/questions/625568/unable-to-delete-registry-key-in-hklm-microsoft-windows-currentversion-run-via-c

Can not run on Angular 10

Implementation

customer-service.component.ts

import * as _ from 'node-machine-id';

ngOnInit(): void { console.log(_);}

package.json

, "browser":{ "child_process": false, "crypto": false }

Error:

Uncaught ReferenceError: process is not defined at Object.<anonymous> (index.js:1) at n (index.js:1) at Object.<anonymous> (index.js:1) at n (index.js:1) at index.js:1 at index.js:1 at index.js:1 at Object.4brq (index.js:1) at __webpack_require__ (bootstrap:84) at Module.kiBU (customer-services.component.ts:3)

Access denied in Windows Electron

I use node-machine-id in an Electron app that is packages with ASAR.

I see users who can't get the machine ID in their app. My error log includes this message:

Error: Error while obtaining machine id: Error: Command failed: %windir%\System32\REG.exe QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid
Zugriff verweigert (= German for 'access denied')

    at ChildProcess.exithandler (node:child_process:406:12)
    at ChildPr...

I thought that the library doesn't use elevated rights. Is this specific to Electron? How can I work around this?

TypeError: (0 , p.exec) is not a function

Uncaught (in promise) TypeError: (0 , p.exec) is not a function
^ Error message

I'm using Electron + ReactJS

Code in use:

import {machineId, machineIdSync} from 'node-machine-id';
let hwid = await machineId()

Rebuild dist and deploy latest version to NPM

I noticed that the latest version on NPM (1.1.10) doesn't have the latest code in master. In fact, the dist/index.js file does not match the source index.js file.

Would you please rebuild dist/index.js and deploy the latest to NPM? Thanks!

Error in importing and packaging node-machine-id with babel

Hi, I'm getting the following error:

import { machineIdSync } from 'node-machine-id';
         ^^^^^^^^^^^^^
SyntaxError: Named export 'machineIdSync' not found. The requested module 'node-machine-id' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'node-machine-id';
const { machineIdSync } = pkg;

    at ModuleJob._instantiate (internal/modules/esm/module_job.js:120:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:165:5)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
 ERROR  Command failed with exit code 1.

If I use:

import nodeMachineId from 'node-machine-id';
const { machineIdSync } = machineIdSync;

the code runs, but I get errors later on (after transpiling with Babel and packaging with pkg)

pkg/prelude/bootstrap.js:1697
      throw error;
      ^

TypeError: Cannot read property 'machineIdSync' of undefined
    at Object.<anonymous> (/snapshot/project/packages/desktop/.babel/storage/server.js:18:46)
    at Module._compile (pkg/prelude/bootstrap.js:1751:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at Module.require (pkg/prelude/bootstrap.js:1676:31)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/snapshot/project/packages/desktop/.babel/index.js:5:15)
    at Module._compile (pkg/prelude/bootstrap.js:1751:22)

Also, this is the transpiled output of the file

var _nodeMachineId = _interopRequireDefault(require("node-machine-id"));
const machineIdSync = _nodeMachineId.default.machineIdSync;

Please drop your suggestions in the comments

Thanks!

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.