diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..faceae6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +target/* +vnt/src/proto/message.rs +vnt-cli/src/generated_serial_number.rs +Cargo.lock \ No newline at end of file diff --git a/common/src/identifier.rs b/common/src/identifier.rs index 94c3520..5a12ae5 100644 --- a/common/src/identifier.rs +++ b/common/src/identifier.rs @@ -51,6 +51,13 @@ pub fn get_unique_identifier() -> Option { #[cfg(target_os = "linux")] pub fn get_unique_identifier() -> Option { use std::process::Command; + + // 对 linux 或 wsl 来说,读取 /etc/machine-id 即可获取当前操作系统的 + // 唯一标识,而且某些环境没有预装`dmidecode`命令 + if let Ok(identifier) = std::fs::read_to_string("/etc/machine-id") { + return Some(identifier); + } + let output = match Command::new("dmidecode") .arg("-s") .arg("system-uuid")