-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 916 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os from 'node:os'
import { $, ProcessOutput } from 'zx'
const HardwareId = async function(){
let sn = ProcessOutput
$.verbose = false
switch (os.platform()) {
case 'win32':
sn = await $`wmic csproduct get`
break
case 'darwin':
sn = await $`system_profiler SPHardwareDataType | grep "Serial"`
break
case 'linux':
if (os.arch() === 'arm') {
sn = await $`cat /proc/cpuinfo | grep UUID`
} else {
sn = await $`dmidecode -t system | grep UUID`
}
break
case 'freebsd':
sn = await $`dmidecode -t system`
break
}
function getImmutableMachineInfo() {
let username = os.userInfo().username,
serial = sn.stdout.split(':')[1].trim(),
platform = os.platform(),
arch = os.arch()
return { username, serial, platform, arch }
}
return getImmutableMachineInfo()
}
export default HardwareId