mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 20:26:47 +02:00
posture: example for macos and windows serial collection
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
fc9051c658
commit
160e3fcb51
@ -531,6 +531,13 @@ func (h *Handler) serveDebugExec(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if cmds[0] == ".serial" {
|
||||
r := posture.GetSerialNumber()
|
||||
response := fmt.Sprintf("serial %+v", r)
|
||||
w.Write([]byte(response))
|
||||
return
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
c := exec.Command(cmds[0], cmds[1:]...)
|
||||
c.Stdout = &out
|
||||
|
||||
26
posture/serial_macos.go
Normal file
26
posture/serial_macos.go
Normal file
@ -0,0 +1,26 @@
|
||||
//go:build darwin && !ios
|
||||
|
||||
package posture
|
||||
|
||||
// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit
|
||||
// #include <CoreFoundation/CoreFoundation.h>
|
||||
// #include <IOKit/IOKitLib.h>
|
||||
//
|
||||
// const char *
|
||||
// getSerialNumber()
|
||||
// {
|
||||
// CFMutableDictionaryRef matching = IOServiceMatching("IOPlatformExpertDevice");
|
||||
// io_service_t service = IOServiceGetMatchingService(NULL, matching);
|
||||
// CFStringRef serialNumber = IORegistryEntryCreateCFProperty(service,
|
||||
// CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0);
|
||||
// const char *str = CFStringGetCStringPtr(serialNumber, kCFStringEncodingUTF8);
|
||||
// IOObjectRelease(service);
|
||||
//
|
||||
// return str;
|
||||
// }
|
||||
import "C"
|
||||
|
||||
func GetSerialNumber() string {
|
||||
serialNumber := C.GoString(C.getSerialNumber())
|
||||
return serialNumber
|
||||
}
|
||||
43
posture/serial_windows.go
Normal file
43
posture/serial_windows.go
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build windows
|
||||
|
||||
package posture
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
)
|
||||
|
||||
type Win32_BIOS struct {
|
||||
SerialNumber string
|
||||
}
|
||||
|
||||
type Win32_BIOS struct {
|
||||
SerialNumber string
|
||||
}
|
||||
|
||||
// GetSerialNumber queries WMI for the availablee serial
|
||||
// numbers of the current device. This will typically be
|
||||
// one, however the query _can_ return multiple.
|
||||
func GetSerialNumber() ([]string, error) {
|
||||
var dst []Win32_BIOS
|
||||
q := wmi.CreateQuery(&dst, "")
|
||||
err := wmi.QueryNamespace(q, &dst, "ROOT\\CIMV2")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to query Windows Management Instrumentation for BIOS info status: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
ret := make([]string, len(dst))
|
||||
for i, v := range dst {
|
||||
ret[i] = v.SerialNumber
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user