How to get a unique PC ID via Electron?
Asked Answered
L

3

22

Is it possible to get a unique PC/Device ID via Electron so I can save PC/Device ID to MySQL Server on the cloud? If this is not possible then what other option I have?

The purpose of this to limit how many device they can use Electron App.

Lanoralanose answered 3/8, 2016 at 20:32 Comment(3)
not 100% reliably, but yes, for most users/use cases you can. Hard drive volume serial, MAC address, etc (neither bulletproof). Might look into canvas-based font fingerprinting, it's pretty solid.Liam
What if you generate a UUID when the app is executed at the first time?. In that case you wouldn't depends on the device and you would be able to identify each app.Lurdan
@PieroDivasto Then save UUID on the cookie and MySQL Server on the cloud?Tessin
N
27

Take a look of the following example.

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({original: true})
// id = 98912984-c4e9-5ceb-8000-03882a0485e4

You can take a look in this package automation-stack/node-machine-id for more details. I think this is what you are looking for.

Ngo answered 8/5, 2018 at 2:38 Comment(0)
E
0

Take a look at the os module in nodejs.

You should be able to string together a few of these values to correctly identify unique PC/Devices.

Elbertina answered 4/8, 2016 at 16:45 Comment(0)
C
0

I created a package to for getting the local machine's MAC address, which should be a good way to get a unique PC id: https://www.npmjs.com/package/macaddress-local-machine

yarn add -D macaddress-local-machine
import macAddr from "macaddress-local-machine";
// Get the first MAC address
const macAddress = macAddr.first();
console.log(macAddress);
// Get all MAC addresses
const macAddresses = macAddr.all();
console.log(macAddresses);

returns one of the following or an array of the following respectively

interface MACAddress {
  iface: string,
  macAddr: string
}

// Example object:
{
  "iface": "eno2",
  "macAddr": "01:23:45:67:89:ab"
}
Chopstick answered 12/6, 2023 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.