-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ssh: fix clientVersion and add uname
- Loading branch information
Showing
13 changed files
with
195 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package version | ||
|
||
type SystemInfo struct { | ||
Name string `json:"name"` | ||
Node string `json:"node"` | ||
Release string `json:"release"` | ||
Version string `json:"version"` | ||
Machine string `json:"machine"` | ||
Domain string `json:"domain,omitempty"` | ||
OS string `json:"os"` | ||
Processor string `json:"processor"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build linux | ||
|
||
package version | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/klauspost/cpuid/v2" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func GetSystemInfo() (*SystemInfo, error) { | ||
var utsname unix.Utsname | ||
if err := unix.Uname(&utsname); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &SystemInfo{ | ||
Name: unix.ByteSliceToString(utsname.Sysname[:]), | ||
Node: unix.ByteSliceToString(utsname.Nodename[:]), | ||
Release: unix.ByteSliceToString(utsname.Release[:]), | ||
Version: unix.ByteSliceToString(utsname.Version[:]), | ||
Machine: unix.ByteSliceToString(utsname.Machine[:]), | ||
Domain: unix.ByteSliceToString(utsname.Domainname[:]), | ||
OS: runtime.GOOS, | ||
Processor: cpuid.CPU.BrandName, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package version | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetSystemInfo(t *testing.T) { | ||
info, err := GetSystemInfo() | ||
if err != nil { | ||
return | ||
} | ||
enc := json.NewEncoder(os.Stderr) | ||
enc.SetIndent("", " ") | ||
_ = enc.Encode(info) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !windows && !linux | ||
|
||
package version | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/klauspost/cpuid/v2" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func GetSystemInfo() (*SystemInfo, error) { | ||
var utsname unix.Utsname | ||
if err := unix.Uname(&utsname); err != nil { | ||
return nil, err | ||
} | ||
return &SystemInfo{ | ||
Name: unix.ByteSliceToString(utsname.Sysname[:]), | ||
Node: unix.ByteSliceToString(utsname.Nodename[:]), | ||
Release: unix.ByteSliceToString(utsname.Release[:]), | ||
Version: unix.ByteSliceToString(utsname.Version[:]), | ||
Machine: unix.ByteSliceToString(utsname.Machine[:]), | ||
OS: runtime.GOOS, | ||
Processor: cpuid.CPU.BrandName, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//go:build windows | ||
|
||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strconv" | ||
"unsafe" | ||
|
||
"github.com/klauspost/cpuid/v2" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
const ( | ||
PROCESSOR_ARCHITECTURE_AMD64 = 9 | ||
PROCESSOR_ARCHITECTURE_ARM = 5 | ||
PROCESSOR_ARCHITECTURE_ARM64 = 12 | ||
PROCESSOR_ARCHITECTURE_IA64 = 6 | ||
PROCESSOR_ARCHITECTURE_INTEL = 0 | ||
) | ||
|
||
var ( | ||
processorArchLists = map[uint16]string{ | ||
PROCESSOR_ARCHITECTURE_AMD64: "x64", | ||
PROCESSOR_ARCHITECTURE_ARM: "arm", | ||
PROCESSOR_ARCHITECTURE_ARM64: "arm64", | ||
PROCESSOR_ARCHITECTURE_IA64: "ia64", | ||
PROCESSOR_ARCHITECTURE_INTEL: "x86", | ||
} | ||
) | ||
|
||
func machineName(i uint16) string { | ||
if n, ok := processorArchLists[i]; ok { | ||
return n | ||
} | ||
return "unknown" | ||
} | ||
|
||
type PROCESSOR_ARCH struct { | ||
ProcessorArchitecture uint16 | ||
Reserved uint16 | ||
} | ||
|
||
type SYSTEM_INFO struct { | ||
Arch PROCESSOR_ARCH | ||
DwPageSize uint32 | ||
LpMinimumApplicationAddress uintptr | ||
LpMaximumApplicationAddress uintptr | ||
DwActiveProcessorMask uint | ||
DwNumberOfProcessors uint32 | ||
DwProcessorType uint32 | ||
DwAllocationGranularity uint32 | ||
WProcessorLevel uint16 | ||
WProcessorRevision uint16 | ||
} | ||
|
||
var ( | ||
kernel32 = windows.NewLazySystemDLL("kernel32.dll") | ||
procGetNativeSystemInfo = kernel32.NewProc("GetNativeSystemInfo") | ||
) | ||
|
||
func GetNativeSystemInfo() *SYSTEM_INFO { | ||
var info SYSTEM_INFO | ||
_, _, _ = procGetNativeSystemInfo.Call(uintptr(unsafe.Pointer(&info))) | ||
return &info | ||
} | ||
|
||
func GetComputerName() (string, error) { | ||
var bufferSize uint32 = 1024 | ||
var buffer [1024]uint16 | ||
if err := windows.GetComputerName(&buffer[0], &bufferSize); err != nil { | ||
return "", nil | ||
} | ||
return windows.UTF16ToString(buffer[:bufferSize]), nil | ||
} | ||
|
||
func GetSystemInfo() (*SystemInfo, error) { | ||
sysinfo := GetNativeSystemInfo() | ||
computerName, _ := GetComputerName() | ||
major, minor, build := windows.RtlGetNtVersionNumbers() | ||
return &SystemInfo{ | ||
Name: "WindowsNT", | ||
Node: computerName, | ||
Release: strconv.FormatUint(uint64(major), 10), | ||
Version: fmt.Sprintf("%d.%d.%d", major, minor, build), | ||
Machine: machineName(sysinfo.Arch.ProcessorArchitecture), | ||
OS: runtime.GOOS, | ||
Processor: cpuid.CPU.BrandName, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters