Skip to content

Commit

Permalink
v0.0.1 - 解耦方便融合怪调用
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 25, 2024
1 parent 86198d1 commit 0242086
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 132 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
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 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Use ```-l``` to specify the output language, currently ```en``` and ```zh``` are

## Usage

下载及安装

```
curl https://raw.githubusercontent.com/oneclickvirt/basics/main/basics_install.sh -sSf | bash
```
Expand All @@ -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
```

使用

```
basics
```


```
./basics
```

进行测试

无环境依赖,理论上适配所有系统和主流架构,更多架构请查看 https://github.com/oneclickvirt/basics/releases/tag/output

```
```

![图片](https://github.com/oneclickvirt/basics/assets/103393591/634064de-17a6-485f-b401-dc3a159a18c4)

![图片](https://github.com/oneclickvirt/basics/assets/103393591/49404a18-1717-4875-b50d-26a930238248)
3 changes: 2 additions & 1 deletion basics_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#From https://github.com/oneclickvirt/basics
#2024.05.21

rm -rf /usr/bin/basics
rm -rf basics
os=$(uname -s)
arch=$(uname -m)
Expand Down Expand Up @@ -106,4 +107,4 @@ FreeBSD)
esac

chmod 777 basics
./basics
cp basics /usr/bin/basics
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import (
"net/http"
"strings"

"github.com/oneclickvirt/basics/model"
"github.com/oneclickvirt/basics/network"
"github.com/oneclickvirt/basics/system"
)

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)")
flag.Parse()
if showVersion {
fmt.Println(model.BasicsVersion)
return
}
var language string
if *languagePtr == "" {
language = "zh"
Expand Down
7 changes: 7 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "testing"

func Test_main(t *testing.T) {
main()
}
35 changes: 0 additions & 35 deletions defaultset/defaultset.go

This file was deleted.

14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module github.com/oneclickvirt/basics

go 1.21.5
go 1.22.4

require (
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/yusufpapurcu/wmi v1.2.4
golang.org/x/sys v0.21.0
)

require (
Expand All @@ -14,16 +18,14 @@ require (
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/koron/go-ssdp v0.0.4 // 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/logging v0.2.2 // indirect
github.com/pion/stun v0.6.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/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/net v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.19.0 // indirect
)
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU=
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/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
Expand All @@ -33,16 +35,19 @@ 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.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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
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/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
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/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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -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.5.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.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
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-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down
61 changes: 61 additions & 0 deletions network/model/model.go → model/model.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package model

const BasicsVersion = "v0.0.1"

var EnableLoger bool

type IpInfo struct {
Ip string
ASN string
Expand Down Expand Up @@ -88,3 +92,60 @@ var TranslationMap = map[string]string{
"IsBogon": "是否Bogon",
"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
}
5 changes: 3 additions & 2 deletions network/baseinfo/baseinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package baseinfo

import (
"fmt"
"github.com/oneclickvirt/basics/network/model"
"github.com/oneclickvirt/basics/network/utils"
"strconv"
"strings"
"sync"

"github.com/oneclickvirt/basics/model"
"github.com/oneclickvirt/basics/network/utils"
)

// FetchIPInfoIo 从 ipinfo.io 获取 IP 信息
Expand Down
4 changes: 2 additions & 2 deletions network/baseinfo/baseinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package baseinfo

import (
"fmt"
networkModel "github.com/oneclickvirt/basics/network/model"
"github.com/oneclickvirt/basics/model"
"testing"
"time"
)

// printIPInfo 重构输出函数
func printIPInfo(ipInfo *networkModel.IpInfo, securityInfo *networkModel.SecurityInfo, err error) {
func printIPInfo(ipInfo *model.IpInfo, securityInfo *model.SecurityInfo, err error) {
if err != nil {
fmt.Println("获取 IP 信息时出错:", err)
return
Expand Down
22 changes: 18 additions & 4 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"fmt"
"strings"

"github.com/oneclickvirt/basics/model"
"github.com/oneclickvirt/basics/network/baseinfo"
"github.com/oneclickvirt/basics/network/model"
. "github.com/oneclickvirt/defaultset"
)

// sortAndTranslateText 对原始文本进行排序和翻译
Expand Down Expand Up @@ -70,9 +71,16 @@ func processPrintIPInfo(headASNString string, headLocationString string, ipResul
// checkType 可选 both ipv4 ipv6
// language 暂时仅支持 en 或 zh
func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (string, string, error) {
if model.EnableLoger {
InitLogger()
defer Logger.Sync()
}
var ipInfo string
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 {
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
}
Expand All @@ -81,13 +89,19 @@ func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (
}
return ipInfo, "", nil
} 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 {
ipInfo += processPrintIPInfo(" IPV4 ASN : ", " IPV4 Location : ", ipInfoV4Result)
}
return ipInfo, "", nil
} 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 {
ipInfo += processPrintIPInfo(" IPV6 ASN : ", " IPV6 Location : ", ipInfoV6Result)
}
Expand Down
Loading

0 comments on commit 0242086

Please sign in to comment.