mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-10-03 07:46:56 +08:00
v0.0.1 - 解耦方便融合怪调用
This commit is contained in:
31
.github/workflows/ci.yaml
vendored
Normal file
31
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: [ '1.22.x' ]
|
||||||
|
os: [ ubuntu-latest ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
- name: Test
|
||||||
|
run: go test ./... -coverprofile=coverage.txt
|
||||||
|
- name: Create Tag
|
||||||
|
if: success() # 仅在测试成功时运行
|
||||||
|
run: |
|
||||||
|
git config --global user.name 'github-actions'
|
||||||
|
git config --global user.email 'github-actions@github.com'
|
||||||
|
TAG="v0.0.1-$(date +'%Y%m%d%H%M%S')"
|
||||||
|
git tag $TAG
|
||||||
|
git push origin $TAG
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
20
README.md
20
README.md
@@ -17,6 +17,8 @@ Use ```-l``` to specify the output language, currently ```en``` and ```zh``` are
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
下载及安装
|
||||||
|
|
||||||
```
|
```
|
||||||
curl https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.sh -sSf | bash
|
curl https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.sh -sSf | bash
|
||||||
```
|
```
|
||||||
@@ -27,8 +29,26 @@ curl https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.s
|
|||||||
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.sh -sSf | bash
|
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.sh -sSf | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
使用
|
||||||
|
|
||||||
|
```
|
||||||
|
basics
|
||||||
|
```
|
||||||
|
|
||||||
|
或
|
||||||
|
|
||||||
|
```
|
||||||
|
./basics
|
||||||
|
```
|
||||||
|
|
||||||
|
进行测试
|
||||||
|
|
||||||
无环境依赖,理论上适配所有系统和主流架构,更多架构请查看 https://github.com/oneclickvirt/basics/releases/tag/output
|
无环境依赖,理论上适配所有系统和主流架构,更多架构请查看 https://github.com/oneclickvirt/basics/releases/tag/output
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#From https://github.com/oneclickvirt/basics
|
#From https://github.com/oneclickvirt/basics
|
||||||
#2024.05.21
|
#2024.05.21
|
||||||
|
|
||||||
|
rm -rf /usr/bin/basics
|
||||||
rm -rf basics
|
rm -rf basics
|
||||||
os=$(uname -s)
|
os=$(uname -s)
|
||||||
arch=$(uname -m)
|
arch=$(uname -m)
|
||||||
@@ -106,4 +107,4 @@ FreeBSD)
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
chmod 777 basics
|
chmod 777 basics
|
||||||
./basics
|
cp basics /usr/bin/basics
|
||||||
|
@@ -6,13 +6,21 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/oneclickvirt/basics/model"
|
||||||
"github.com/oneclickvirt/basics/network"
|
"github.com/oneclickvirt/basics/network"
|
||||||
"github.com/oneclickvirt/basics/system"
|
"github.com/oneclickvirt/basics/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var showVersion bool
|
||||||
|
flag.BoolVar(&showVersion, "v", false, "show version")
|
||||||
|
flag.BoolVar(&model.EnableLoger, "e", false, "Enable logging")
|
||||||
languagePtr := flag.String("l", "", "Language parameter (en or zh)")
|
languagePtr := flag.String("l", "", "Language parameter (en or zh)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if showVersion {
|
||||||
|
fmt.Println(model.BasicsVersion)
|
||||||
|
return
|
||||||
|
}
|
||||||
var language string
|
var language string
|
||||||
if *languagePtr == "" {
|
if *languagePtr == "" {
|
||||||
language = "zh"
|
language = "zh"
|
||||||
|
7
cmd/main_test.go
Normal file
7
cmd/main_test.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test_main(t *testing.T) {
|
||||||
|
main()
|
||||||
|
}
|
@@ -1,35 +0,0 @@
|
|||||||
package defaultset
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func Red(text string) string {
|
|
||||||
return fmt.Sprintf("\033[31m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Green(text string) string {
|
|
||||||
return fmt.Sprintf("\033[32m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DarkGreen(text string) string {
|
|
||||||
return fmt.Sprintf("\033[32m\033[02m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Yellow(text string) string {
|
|
||||||
return fmt.Sprintf("\033[33m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Blue(text string) string {
|
|
||||||
return fmt.Sprintf("\033[36m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Purple(text string) string {
|
|
||||||
return fmt.Sprintf("\033[35m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Cyan(text string) string {
|
|
||||||
return fmt.Sprintf("\033[36m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func White(text string) string {
|
|
||||||
return fmt.Sprintf("\033[37m\033[01m%s\033[0m", text)
|
|
||||||
}
|
|
14
go.mod
14
go.mod
@@ -1,10 +1,14 @@
|
|||||||
module github.com/oneclickvirt/basics
|
module github.com/oneclickvirt/basics
|
||||||
|
|
||||||
go 1.21.5
|
go 1.22.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/libp2p/go-nat v0.2.0
|
github.com/libp2p/go-nat v0.2.0
|
||||||
|
github.com/pion/logging v0.2.2
|
||||||
|
github.com/pion/stun v0.6.1
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
|
github.com/yusufpapurcu/wmi v1.2.4
|
||||||
|
golang.org/x/sys v0.21.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -14,16 +18,14 @@ require (
|
|||||||
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||||
github.com/koron/go-ssdp v0.0.4 // indirect
|
github.com/koron/go-ssdp v0.0.4 // indirect
|
||||||
github.com/libp2p/go-netroute v0.2.1 // indirect
|
github.com/libp2p/go-netroute v0.2.1 // indirect
|
||||||
|
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 // indirect
|
||||||
github.com/pion/dtls/v2 v2.2.7 // indirect
|
github.com/pion/dtls/v2 v2.2.7 // indirect
|
||||||
github.com/pion/logging v0.2.2 // indirect
|
|
||||||
github.com/pion/stun v0.6.1 // indirect
|
|
||||||
github.com/pion/transport/v2 v2.2.1 // indirect
|
github.com/pion/transport/v2 v2.2.1 // indirect
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
|
||||||
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
||||||
github.com/tklauser/numcpus v0.8.0 // indirect
|
github.com/tklauser/numcpus v0.8.0 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
golang.org/x/crypto v0.8.0 // indirect
|
golang.org/x/crypto v0.8.0 // indirect
|
||||||
golang.org/x/net v0.10.0 // indirect
|
golang.org/x/net v0.10.0 // indirect
|
||||||
golang.org/x/sync v0.2.0 // indirect
|
golang.org/x/sync v0.2.0 // indirect
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
13
go.sum
13
go.sum
@@ -15,6 +15,8 @@ github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk=
|
|||||||
github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk=
|
github.com/libp2p/go-nat v0.2.0/go.mod h1:3MJr+GRpRkyT65EpVPBstXLvOlAPzUVlG6Pwg9ohLJk=
|
||||||
github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU=
|
github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU=
|
||||||
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
||||||
|
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
|
||||||
|
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
|
||||||
github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8=
|
github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8=
|
||||||
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
|
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
|
||||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
||||||
@@ -33,9 +35,8 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
|
|||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
|
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
|
||||||
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
|
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
|
||||||
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
|
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
|
||||||
@@ -43,6 +44,10 @@ github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8t
|
|||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
|
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||||
|
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
|
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||||
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
@@ -75,8 +80,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
const BasicsVersion = "v0.0.1"
|
||||||
|
|
||||||
|
var EnableLoger bool
|
||||||
|
|
||||||
type IpInfo struct {
|
type IpInfo struct {
|
||||||
Ip string
|
Ip string
|
||||||
ASN string
|
ASN string
|
||||||
@@ -88,3 +92,60 @@ var TranslationMap = map[string]string{
|
|||||||
"IsBogon": "是否Bogon",
|
"IsBogon": "是否Bogon",
|
||||||
"IsBot": "是否机器人",
|
"IsBot": "是否机器人",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CpuInfo struct {
|
||||||
|
CpuModel string
|
||||||
|
CpuCores string
|
||||||
|
CpuCache string
|
||||||
|
CpuAesNi string
|
||||||
|
CpuVAH string
|
||||||
|
}
|
||||||
|
|
||||||
|
type MemoryInfo struct {
|
||||||
|
MemoryUsage string
|
||||||
|
MemoryTotal string
|
||||||
|
SwapUsage string
|
||||||
|
SwapTotal string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DiskInfo struct {
|
||||||
|
DiskUsage string
|
||||||
|
DiskTotal string
|
||||||
|
Percentage string
|
||||||
|
BootPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SystemInfo struct {
|
||||||
|
CpuInfo
|
||||||
|
MemoryInfo
|
||||||
|
DiskInfo
|
||||||
|
Platform string // 系统名字 Distro1
|
||||||
|
PlatformVersion string // 系统版本 Distro2
|
||||||
|
Kernel string // 系统内核
|
||||||
|
Arch string //
|
||||||
|
Uptime string // 正常运行时间
|
||||||
|
TimeZone string // 系统时区
|
||||||
|
VmType string // 虚拟化架构
|
||||||
|
Load string // load1 load2 load3
|
||||||
|
NatType string // stun
|
||||||
|
VirtioBalloon string // 气球驱动
|
||||||
|
KSM string // 内存合并
|
||||||
|
TcpAccelerationMethod string // TCP拥塞控制
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_Processor struct {
|
||||||
|
L2CacheSize uint32
|
||||||
|
L3CacheSize uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_ComputerSystem struct {
|
||||||
|
SystemType string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_OperatingSystem struct {
|
||||||
|
BuildType string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_TimeZone struct {
|
||||||
|
Caption string
|
||||||
|
}
|
@@ -2,11 +2,12 @@ package baseinfo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/oneclickvirt/basics/network/model"
|
|
||||||
"github.com/oneclickvirt/basics/network/utils"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/oneclickvirt/basics/model"
|
||||||
|
"github.com/oneclickvirt/basics/network/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FetchIPInfoIo 从 ipinfo.io 获取 IP 信息
|
// FetchIPInfoIo 从 ipinfo.io 获取 IP 信息
|
||||||
|
@@ -2,13 +2,13 @@ package baseinfo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
networkModel "github.com/oneclickvirt/basics/network/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// printIPInfo 重构输出函数
|
// printIPInfo 重构输出函数
|
||||||
func printIPInfo(ipInfo *networkModel.IpInfo, securityInfo *networkModel.SecurityInfo, err error) {
|
func printIPInfo(ipInfo *model.IpInfo, securityInfo *model.SecurityInfo, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("获取 IP 信息时出错:", err)
|
fmt.Println("获取 IP 信息时出错:", err)
|
||||||
return
|
return
|
||||||
|
@@ -4,8 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/oneclickvirt/basics/model"
|
||||||
"github.com/oneclickvirt/basics/network/baseinfo"
|
"github.com/oneclickvirt/basics/network/baseinfo"
|
||||||
"github.com/oneclickvirt/basics/network/model"
|
. "github.com/oneclickvirt/defaultset"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sortAndTranslateText 对原始文本进行排序和翻译
|
// sortAndTranslateText 对原始文本进行排序和翻译
|
||||||
@@ -70,9 +71,16 @@ func processPrintIPInfo(headASNString string, headLocationString string, ipResul
|
|||||||
// checkType 可选 both ipv4 ipv6
|
// checkType 可选 both ipv4 ipv6
|
||||||
// language 暂时仅支持 en 或 zh
|
// language 暂时仅支持 en 或 zh
|
||||||
func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (string, string, error) {
|
func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (string, string, error) {
|
||||||
|
if model.EnableLoger {
|
||||||
|
InitLogger()
|
||||||
|
defer Logger.Sync()
|
||||||
|
}
|
||||||
var ipInfo string
|
var ipInfo string
|
||||||
if checkType == "both" {
|
if checkType == "both" {
|
||||||
ipInfoV4Result, _, ipInfoV6Result, _, _ := baseinfo.RunIpCheck("both")
|
ipInfoV4Result, _, ipInfoV6Result, _, err := baseinfo.RunIpCheck("both")
|
||||||
|
if err != nil && model.EnableLoger {
|
||||||
|
Logger.Info(err.Error())
|
||||||
|
}
|
||||||
if ipInfoV4Result != nil {
|
if ipInfoV4Result != nil {
|
||||||
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
|
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
|
||||||
}
|
}
|
||||||
@@ -81,13 +89,19 @@ func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (
|
|||||||
}
|
}
|
||||||
return ipInfo, "", nil
|
return ipInfo, "", nil
|
||||||
} else if checkType == "ipv4" {
|
} else if checkType == "ipv4" {
|
||||||
ipInfoV4Result, _, _, _, _ := baseinfo.RunIpCheck("ipv4")
|
ipInfoV4Result, _, _, _, err := baseinfo.RunIpCheck("ipv4")
|
||||||
|
if err != nil && model.EnableLoger {
|
||||||
|
Logger.Info(err.Error())
|
||||||
|
}
|
||||||
if ipInfoV4Result != nil {
|
if ipInfoV4Result != nil {
|
||||||
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
|
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
|
||||||
}
|
}
|
||||||
return ipInfo, "", nil
|
return ipInfo, "", nil
|
||||||
} else if checkType == "ipv6" {
|
} else if checkType == "ipv6" {
|
||||||
_, _, ipInfoV6Result, _, _ := baseinfo.RunIpCheck("ipv6")
|
_, _, ipInfoV6Result, _, err := baseinfo.RunIpCheck("ipv6")
|
||||||
|
if err != nil && model.EnableLoger {
|
||||||
|
Logger.Info(err.Error())
|
||||||
|
}
|
||||||
if ipInfoV6Result != nil {
|
if ipInfoV6Result != nil {
|
||||||
ipInfo += processPrintIPInfo(" IPV6 ASN : ", " IPV6 Location : ", ipInfoV6Result)
|
ipInfo += processPrintIPInfo(" IPV6 ASN : ", " IPV6 Location : ", ipInfoV6Result)
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
networkModel "github.com/oneclickvirt/basics/network/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// chooseString 用于选择非空字符串
|
// chooseString 用于选择非空字符串
|
||||||
@@ -15,12 +15,12 @@ func chooseString(src, dst string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CompareAndMergeIpInfo 用于比较和合并两个 IpInfo 结构体
|
// CompareAndMergeIpInfo 用于比较和合并两个 IpInfo 结构体
|
||||||
func CompareAndMergeIpInfo(dst, src *networkModel.IpInfo) (res *networkModel.IpInfo, err error) {
|
func CompareAndMergeIpInfo(dst, src *model.IpInfo) (res *model.IpInfo, err error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, fmt.Errorf("Error merge IpInfo")
|
return nil, fmt.Errorf("Error merge IpInfo")
|
||||||
}
|
}
|
||||||
if dst == nil {
|
if dst == nil {
|
||||||
dst = &networkModel.IpInfo{}
|
dst = &model.IpInfo{}
|
||||||
}
|
}
|
||||||
dst.Ip = chooseString(src.Ip, dst.Ip)
|
dst.Ip = chooseString(src.Ip, dst.Ip)
|
||||||
dst.ASN = chooseString(src.ASN, dst.ASN)
|
dst.ASN = chooseString(src.ASN, dst.ASN)
|
||||||
@@ -32,12 +32,12 @@ func CompareAndMergeIpInfo(dst, src *networkModel.IpInfo) (res *networkModel.IpI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CompareAndMergeSecurityInfo 用于比较和合并两个 SecurityInfo 结构体
|
// CompareAndMergeSecurityInfo 用于比较和合并两个 SecurityInfo 结构体
|
||||||
func CompareAndMergeSecurityInfo(dst, src *networkModel.SecurityInfo) (res *networkModel.SecurityInfo, err error) {
|
func CompareAndMergeSecurityInfo(dst, src *model.SecurityInfo) (res *model.SecurityInfo, err error) {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
return nil, fmt.Errorf("Error merge SecurityInfo")
|
return nil, fmt.Errorf("Error merge SecurityInfo")
|
||||||
}
|
}
|
||||||
if dst == nil {
|
if dst == nil {
|
||||||
dst = &networkModel.SecurityInfo{}
|
dst = &model.SecurityInfo{}
|
||||||
}
|
}
|
||||||
dst.IsAbuser = chooseString(src.IsAbuser, dst.IsAbuser)
|
dst.IsAbuser = chooseString(src.IsAbuser, dst.IsAbuser)
|
||||||
dst.IsAttacker = chooseString(src.IsAttacker, dst.IsAttacker)
|
dst.IsAttacker = chooseString(src.IsAttacker, dst.IsAttacker)
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
networkModel "github.com/oneclickvirt/basics/network/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseIpInfo(data map[string]interface{}) *networkModel.IpInfo {
|
func ParseIpInfo(data map[string]interface{}) *model.IpInfo {
|
||||||
ipInfo := &networkModel.IpInfo{}
|
ipInfo := &model.IpInfo{}
|
||||||
if ip, ok := data["ip"].(string); ok {
|
if ip, ok := data["ip"].(string); ok {
|
||||||
ipInfo.Ip = ip
|
ipInfo.Ip = ip
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,8 @@ func ParseIpInfo(data map[string]interface{}) *networkModel.IpInfo {
|
|||||||
return ipInfo
|
return ipInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseSecurityInfo(data map[string]interface{}) *networkModel.SecurityInfo {
|
func ParseSecurityInfo(data map[string]interface{}) *model.SecurityInfo {
|
||||||
securityInfo := &networkModel.SecurityInfo{}
|
securityInfo := &model.SecurityInfo{}
|
||||||
if security, ok := data["security"].(map[string]interface{}); ok {
|
if security, ok := data["security"].(map[string]interface{}); ok {
|
||||||
if isAbuser, ok := security["is_abuser"].(bool); ok {
|
if isAbuser, ok := security["is_abuser"].(bool); ok {
|
||||||
securityInfo.IsAbuser = strconv.FormatBool(isAbuser)
|
securityInfo.IsAbuser = strconv.FormatBool(isAbuser)
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/oneclickvirt/basics/system/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
"github.com/oneclickvirt/basics/system/utils"
|
"github.com/oneclickvirt/basics/system/utils"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
)
|
)
|
||||||
|
@@ -10,8 +10,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// getDiskInfo 获取硬盘信息
|
// getDiskInfo 获取硬盘信息
|
||||||
func getDiskInfo() (string, string, string, error) {
|
func getDiskInfo() (string, string, string, string, error) {
|
||||||
var diskTotalStr, diskUsageStr, bootPath string
|
var diskTotalStr, diskUsageStr, percentageStr, bootPath string
|
||||||
tempDiskTotal, tempDiskUsage := getDiskTotalAndUsed()
|
tempDiskTotal, tempDiskUsage := getDiskTotalAndUsed()
|
||||||
diskTotalGB := float64(tempDiskTotal) / (1024 * 1024 * 1024)
|
diskTotalGB := float64(tempDiskTotal) / (1024 * 1024 * 1024)
|
||||||
diskUsageGB := float64(tempDiskUsage) / (1024 * 1024 * 1024)
|
diskUsageGB := float64(tempDiskUsage) / (1024 * 1024 * 1024)
|
||||||
@@ -69,9 +69,11 @@ func getDiskInfo() (string, string, string, error) {
|
|||||||
diskTotalGB = float64(tpDiskTotal) / (1024 * 1024)
|
diskTotalGB = float64(tpDiskTotal) / (1024 * 1024)
|
||||||
diskUsageGB = float64(tpDiskUsage) / (1024 * 1024)
|
diskUsageGB = float64(tpDiskUsage) / (1024 * 1024)
|
||||||
if diskTotalGB < 1 {
|
if diskTotalGB < 1 {
|
||||||
diskTotalStr = strconv.FormatFloat(diskTotalGB*1024, 'f', 2, 64) + " MB" + " [" + nonEmptyFields[4] + "]"
|
diskTotalStr = strconv.FormatFloat(diskTotalGB*1024, 'f', 2, 64) + " MB"
|
||||||
|
percentageStr = nonEmptyFields[4]
|
||||||
} else {
|
} else {
|
||||||
diskTotalStr = strconv.FormatFloat(diskTotalGB, 'f', 2, 64) + " GB" + " [" + nonEmptyFields[4] + "]"
|
diskTotalStr = strconv.FormatFloat(diskTotalGB, 'f', 2, 64) + " GB"
|
||||||
|
percentageStr = nonEmptyFields[4]
|
||||||
}
|
}
|
||||||
if diskUsageGB < 1 {
|
if diskUsageGB < 1 {
|
||||||
diskUsageStr = strconv.FormatFloat(diskUsageGB*1024, 'f', 2, 64) + " MB"
|
diskUsageStr = strconv.FormatFloat(diskUsageGB*1024, 'f', 2, 64) + " MB"
|
||||||
@@ -84,7 +86,11 @@ func getDiskInfo() (string, string, string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return diskTotalStr, diskUsageStr, bootPath, nil
|
// 两个%避免被转义
|
||||||
|
if percentageStr != "" && strings.Contains(percentageStr, "%") {
|
||||||
|
percentageStr = strings.ReplaceAll(percentageStr, "%", "%%")
|
||||||
|
}
|
||||||
|
return diskTotalStr, diskUsageStr, percentageStr, bootPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDiskTotalAndUsed() (total uint64, used uint64) {
|
func getDiskTotalAndUsed() (total uint64, used uint64) {
|
||||||
|
@@ -1,57 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
type CpuInfo struct {
|
|
||||||
CpuModel string
|
|
||||||
CpuCores string
|
|
||||||
CpuCache string
|
|
||||||
CpuAesNi string
|
|
||||||
CpuVAH string
|
|
||||||
}
|
|
||||||
|
|
||||||
type MemoryInfo struct {
|
|
||||||
MemoryUsage string
|
|
||||||
MemoryTotal string
|
|
||||||
SwapUsage string
|
|
||||||
SwapTotal string
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiskInfo struct {
|
|
||||||
DiskUsage string
|
|
||||||
DiskTotal string
|
|
||||||
BootPath string
|
|
||||||
}
|
|
||||||
|
|
||||||
type SystemInfo struct {
|
|
||||||
CpuInfo
|
|
||||||
MemoryInfo
|
|
||||||
DiskInfo
|
|
||||||
Platform string // 系统名字 Distro1
|
|
||||||
PlatformVersion string // 系统版本 Distro2
|
|
||||||
Kernel string // 系统内核
|
|
||||||
Arch string //
|
|
||||||
Uptime string // 正常运行时间
|
|
||||||
TimeZone string // 系统时区
|
|
||||||
VmType string // 虚拟化架构
|
|
||||||
Load string // load1 load2 load3
|
|
||||||
NatType string // stun
|
|
||||||
VirtioBalloon string // 气球驱动
|
|
||||||
KSM string // 内存合并
|
|
||||||
TcpAccelerationMethod string // TCP拥塞控制
|
|
||||||
}
|
|
||||||
|
|
||||||
type Win32_Processor struct {
|
|
||||||
L2CacheSize uint32
|
|
||||||
L3CacheSize uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
type Win32_ComputerSystem struct {
|
|
||||||
SystemType string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Win32_OperatingSystem struct {
|
|
||||||
BuildType string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Win32_TimeZone struct {
|
|
||||||
Caption string
|
|
||||||
}
|
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/oneclickvirt/basics/system/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
"github.com/oneclickvirt/basics/system/utils"
|
"github.com/oneclickvirt/basics/system/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func GetSystemInfo() *model.SystemInfo {
|
|||||||
// CPU信息查询
|
// CPU信息查询
|
||||||
ret, _ = getCpuInfo(ret, cpuType)
|
ret, _ = getCpuInfo(ret, cpuType)
|
||||||
// 硬盘信息查询
|
// 硬盘信息查询
|
||||||
ret.DiskTotal, ret.DiskUsage, ret.BootPath, _ = getDiskInfo()
|
ret.DiskTotal, ret.DiskUsage, ret.Percentage, ret.BootPath, _ = getDiskInfo()
|
||||||
// 内存信息查询
|
// 内存信息查询
|
||||||
ret.MemoryTotal, ret.MemoryUsage, ret.SwapTotal, ret.SwapUsage, ret.VirtioBalloon, ret.KSM = getMemoryInfo()
|
ret.MemoryTotal, ret.MemoryUsage, ret.SwapTotal, ret.SwapUsage, ret.VirtioBalloon, ret.KSM = getMemoryInfo()
|
||||||
// 获取负载信息
|
// 获取负载信息
|
||||||
@@ -65,7 +65,12 @@ func CheckSystemInfo(language string) string {
|
|||||||
} else if ret.SwapTotal != "" && ret.SwapUsage != "" {
|
} else if ret.SwapTotal != "" && ret.SwapUsage != "" {
|
||||||
res += " Swap : " + ret.SwapUsage + " / " + ret.SwapTotal + "\n"
|
res += " Swap : " + ret.SwapUsage + " / " + ret.SwapTotal + "\n"
|
||||||
}
|
}
|
||||||
res += " Disk : " + ret.DiskUsage + " / " + ret.DiskTotal + "\n"
|
res += " Disk : " + ret.DiskUsage + " / " + ret.DiskTotal
|
||||||
|
if ret.Percentage != "" {
|
||||||
|
res += " [" + ret.Percentage + "] " + "\n"
|
||||||
|
} else {
|
||||||
|
res += "\n"
|
||||||
|
}
|
||||||
res += " Boot Path : " + ret.BootPath + "\n"
|
res += " Boot Path : " + ret.BootPath + "\n"
|
||||||
res += " OS Release : " + ret.Platform + " [" + ret.Arch + "] " + "\n"
|
res += " OS Release : " + ret.Platform + " [" + ret.Arch + "] " + "\n"
|
||||||
if ret.Kernel != "" {
|
if ret.Kernel != "" {
|
||||||
@@ -101,7 +106,12 @@ func CheckSystemInfo(language string) string {
|
|||||||
} else if ret.SwapTotal != "" && ret.SwapUsage != "" {
|
} else if ret.SwapTotal != "" && ret.SwapUsage != "" {
|
||||||
res += " Swap : " + ret.SwapUsage + " / " + ret.SwapTotal + "\n"
|
res += " Swap : " + ret.SwapUsage + " / " + ret.SwapTotal + "\n"
|
||||||
}
|
}
|
||||||
res += " 硬盘空间 : " + ret.DiskUsage + " / " + ret.DiskTotal + "\n"
|
res += " 硬盘空间 : " + ret.DiskUsage + " / " + ret.DiskTotal
|
||||||
|
if ret.Percentage != "" {
|
||||||
|
res += " [" + ret.Percentage + "] " + "\n"
|
||||||
|
} else {
|
||||||
|
res += "\n"
|
||||||
|
}
|
||||||
res += " 启动盘路径 : " + ret.BootPath + "\n"
|
res += " 启动盘路径 : " + ret.BootPath + "\n"
|
||||||
res += " 系统 : " + ret.Platform + " [" + ret.Arch + "] " + "\n"
|
res += " 系统 : " + ret.Platform + " [" + ret.Arch + "] " + "\n"
|
||||||
if ret.Kernel != "" {
|
if ret.Kernel != "" {
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/oneclickvirt/basics/system/model"
|
"github.com/oneclickvirt/basics/model"
|
||||||
"github.com/yusufpapurcu/wmi"
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user