Recently, there is a need to generate a unique ID bound to the computer. There are many conventional solutions on the Internet, such as:
- MAC address: very good, but you will encounter multiple network cards
- CPU SN/ID: Now most CPUs only have Family ID, no SN, so CPUs of the same model will be duplicated
- Hard disk ID: It may be unique, but now there are generally multiple hard disks
- Motherboard ID? That's a good idea, but the motherboard has a lot of information, which one can do? Generally, the motherboard SN and UUID can be considered
- OS UUID: Contains the UUID generated during installation and the product UUID (Windows platform), which does not seem to be applicable to Linux, etc.
Considering the requirement of cross-platform, it is most reliable to obtain motherboard BIOS information through dmi at present, and then you can consider adding MAC or hard disk ID.
Refer to other people's implementation:
https://blog.csdn.net/gobest28/article/details/84561602
https://www.jianshu.com/p/2e7ce2946b6b
Obtain the motherboard bmi information directly through the cross-platform solution, and get the CPU and motherboard characteristics: (MAC and hard disk need to be obtained in other ways)
package main
import (
"fmt"
"os"
"github.com/yumaojun03/dmidecode"
)
func checkError(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
// https://blog.csdn.net/gobest28/article/details/84561602
// https://www.jianshu.com/p/2e7ce2946b6b
func main() {
// 主板smBIOS UUID
// MachineGUID
// MAC地址
// 硬盘序列号
dmi, err := dmidecode.New()
checkError(err)
infos, err := dmi.ALL()
infos.Print()
}
The approximate output is as follows:
Handle e, DMI type 0, 24 bytes
BIOS Information
Vendor: LENOVO
Version: N1EET98W (1.71 )
Release Date: 12/06/2022
Address: 0xE0000
Runtime Size: 128 kB
ROM Size: 0 kB
Characteristics:
PCI is supported
PNP is supported
BIOS is upgradeable
BIOS shadowing is allowed
Boot from CD is supported
Selectable boot is supported
EDD is supported
3.5"/720 kB floppy services are supported (int 13h)
Print screen service is supported (int 5h)
8042 keyboard services are supported (int 9h)
Serial services are supported (int 14h)
Printer services are supported (int 17h)
CGA/mono video services are supported (int 10h)
ACPI is supported
I2O boot is supported
BIOS boot specification is supported
Targeted content distribution is supported
UEFI is supported
System is a virtual machine
Handle f, DMI type 1, 27 bytes
System Information
Manufacturer: LENOVO
Product Name: 20EQS0T70G
Version: ThinkPad P50
Serial Number: PC0X7A0M
UUID: 33EC83CC-315A-11B2-A85C-E9065B388106
Wake-up Type: Power Switch
SKU Number: LENOVO_MT_20EQ_BU_Think_FM_ThinkPad P50
Family: ThinkPad P50
xxx,9Base Board Information
Manufacturer: LENOVO
Product Name: 20EQS0T70G
Version: SDK0J40675 WIN
Serial Number: L1HF88F00E2
Asset Tag: Not Available
Features:
Board is a hosting board
Board is replaceable
Location In Chassis: Not Available
Type: Motherboard
Chassis Information
Manufacturer: LENOVO
Type: Notebook
Lock: Not Present
Version: None
Serial Number: PC0X7A0M
Asset Tag: No Asset Information
Boot-up State: Unknown
Power Supply State: Unknown
Thermal State: Unknown
Security Status: Unknown
OEM Information: 0
Height: Not Specified
Number Of Power Cords: 0
Contained Elements: {0 0 0}
SKU Number: No Asset Information
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: USB 1
External Connector Type: Access Bus (USB)
Type: USB
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: USB 2
External Connector Type: Access Bus (USB)
Type: USB
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: USB 3
External Connector Type: Access Bus (USB)
Type: USB
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Ethernet
External Connector Type: RJ-45
Type: Network Port
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Hdmi
External Connector Type: %!s(PANIC=String method: runtime error: index out of range [255] with length 41)
Type: Video Port
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Mini DisplayPort
External Connector Type: %!s(PANIC=String method: runtime error: index out of range [255] with length 41)
Type: Video Port
Port Information
Internal Reference Designator: Not Available
Internal Connector Type: None
External Reference Designator: Headphone/Microphone Combo Jack1
External Connector Type: Mini-jack (headphones)
Type: Audio Port
Processor Information
Socket Designation: U3E1
Processor Type: CentralProcessor
Family: Dual-Core Intel® Celeron® processor
Manufacturer: Intel(R) Corporation
ID: E3 06 05 00 FF FB EB BF
Version: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Voltage: 1.0
External Clock: 100
Max Speed: 8300
Current Speed: 2700
Status: Populated,CPU Enabled
Upgrade: Unknown
L1 Cache Handle: 4
L2 Cache Handle: 5
L3 Cache Handle: 406
Serial Number: None
Asset Tag: None
Part Number: None
Core Count: 4
Core Enabled: 4
Thread Count: 8
Characteristics: 64-bit Capable,Multi-Core,Hardware Thread,Execute Protection,Enhanced Virtualization,Power/Performance Control
Family2: Dual-Core Intel® Celeron® processor
Cache Information
Socket Designation: L1 Cache
Configuration: Cache Configuration:
Level: Level1
Socketed: false
Location: Internal
Enabled: false
Mode: Write Back
Maximum Cache Size: 128 * 1K
Installed Size: 128 * 1K
SupportedSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
CurrentSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
Cache Speed: 0
Error Correction Type: Parity
System Cache Type: Data
Associativity: 16-way Set-Associative
Cache Information
Socket Designation: L1 Cache
Configuration: Cache Configuration:
Level: Level1
Socketed: false
Location: Internal
Enabled: false
Mode: Write Back
Maximum Cache Size: 128 * 1K
Installed Size: 128 * 1K
SupportedSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
CurrentSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
Cache Speed: 0
Error Correction Type: Parity
System Cache Type: Instruction
Associativity: 16-way Set-Associative
Cache Information
Socket Designation: L2 Cache
Configuration: Cache Configuration:
Level: Level2
Socketed: false
Location: Internal
Enabled: false
Mode: Write Back
Maximum Cache Size: 1024 * 1K
Installed Size: 1024 * 1K
SupportedSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
CurrentSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
Cache Speed: 0
Error Correction Type: Single-bit ECC
System Cache Type: Unified
Associativity: Fully Associative
Cache Information
Socket Designation: L3 Cache
Configuration: Cache Configuration:
Level: Level3
Socketed: false
Location: Internal
Enabled: false
Mode: Write Back
Maximum Cache Size: 8192 * 1K
Installed Size: 8192 * 1K
SupportedSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
CurrentSRAM Type: %!s(PANIC=String method: runtime error: index out of range [16] with length 8)
Cache Speed: 0
Error Correction Type: Multi-bit ECC
System Cache Type: Unified
Associativity: 12-way Set-Associative
Physcial Memory Array
Location: System board or motherboard
Use: System memory
Memory Error Correction: None
Maximum Capacity: 67108864
Memory Error Information Handle: 65534
Number of Memory Devices: 4
Extended Maximum Capacity: 0
Memory Device
Physical Memory Array Handle: 8
Memory Error Information Handle: 65534
Total Width: 64
Data Width: 64
Size: 8192
Form Factor: SODIMM
Device Set: 0
Device Locator: ChannelA-DIMM0
Bank Locator: BANK 0
Memory Type: DDR4
Type Detail: Synchronous
Speed: 2133
Manufacturer: Samsung
Serial Number: 4031B912
Asset Tag:
Part Number: M471A1K43CB1-CRC
Attributes: 1
Extended Size: 0
Configured Memory Clock Speed: 2133
Minimum voltage: 0
Maximum voltage: 0
Configured voltage: 0
Memory Device
Physical Memory Array Handle: 8
Memory Error Information Handle: 65534
Total Width: 0
Data Width: 0
Size: 0
Form Factor: Unknown
Device Set: 0
Device Locator: ChannelA-DIMM1
Bank Locator: BANK 1
Memory Type: Unknown
Type Detail:
Speed: 0
Manufacturer: Unknown
Serial Number: Unknown
Asset Tag:
Part Number: Unknown
Attributes: 0
Extended Size: 0
Configured Memory Clock Speed: 0
Minimum voltage: 0
Maximum voltage: 0
Configured voltage: 0
Memory Device
Physical Memory Array Handle: 8
Memory Error Information Handle: 65534
Total Width: 64
Data Width: 64
Size: 8192
Form Factor: SODIMM
Device Set: 0
Device Locator: ChannelB-DIMM0
Bank Locator: BANK 2
Memory Type: DDR4
Type Detail: Synchronous
Speed: 2133
Manufacturer: Samsung
Serial Number: 4031BBAD
Asset Tag:
Part Number: M471A1K43CB1-CRC
Attributes: 1
Extended Size: 0
Configured Memory Clock Speed: 2133
Minimum voltage: 0
Maximum voltage: 0
Configured voltage: 0
Memory Device
Physical Memory Array Handle: 8
Memory Error Information Handle: 65534
Total Width: 64
Data Width: 64
Size: 16384
Form Factor: SODIMM
Device Set: 0
Device Locator: ChannelB-DIMM1
Bank Locator: BANK 3
Memory Type: DDR4
Type Detail: Synchronous
Speed: 2133
Manufacturer: 0443
Serial Number: 1278952B
Asset Tag:
Part Number: RMSA3300MH78HBF-2666
Attributes: 2
Extended Size: 0
Configured Memory Clock Speed: 2133
Minimum voltage: 0
Maximum voltage: 0
Configured voltage: 0
System Slot 0
Slot Designation: Media Card Slot
Slot Type: Other
Slot Data Bus Width: Other
Current Usage: Available
Slot Length: Other
Slot ID: 0
Slot Characteristics1: Characteristics unknown.
Slot Characteristics2: Slot supports hot-plug devices.
Segment Group Number: 0
Bus Number: 0
Device/Function Number: 0
System Slot 0
Slot Designation: SmartCard Slot
Slot Type: Other
Slot Data Bus Width: Other
Current Usage: Available
Slot Length: Other
Slot ID: 0
Slot Characteristics1: Characteristics unknown.
Slot Characteristics2: Slot supports hot-plug devices.
Segment Group Number: 0
Bus Number: 0
Device/Function Number: 0
System Slot 0
Slot Designation: SimCard Slot
Slot Type: Other
Slot Data Bus Width: Other
Current Usage: Available
Slot Length: Other
Slot ID: 0
Slot Characteristics1: Characteristics unknown.
Slot Characteristics2: PCI slot supports Power Management Event (PME#) signal.
Segment Group Number: 0
Bus Number: 0
Device/Function Number: 0