Compare commits

...

13 Commits

Author SHA1 Message Date
spiritlhl
ac33e00e0a fix: 拆分main函数,分函数方便后续维护,添加前置检测自动切换离线模式 2025-06-29 06:27:59 +00:00
spiritlhl
7a439f7095 fix: 优化编译文件的大小 2025-06-29 10:55:39 +08:00
spiritlhl
e3bfa65f66 Merge pull request #12 from fossabot/add-license-scan-badge
Add license scan report and status
2025-06-29 09:36:58 +08:00
fossabot
74e33a212c Add license scan report and status
Signed off by: fossabot <badges@fossa.com>
2025-06-28 21:22:21 -04:00
spiritlhl
bba8595033 fix: 统一致谢图标大小 2025-06-29 01:00:05 +00:00
spiritlhl
530181be87 feat: 添加zmto对本开源项目的支持 2025-06-29 00:57:46 +00:00
github-actions[bot]
7deb986209 chore: update ECS_VERSION to 0.1.37 in goecs.sh 2025-06-28 14:02:18 +00:00
spiritlhl
ea8e5efbd3 fix: 修复部分失效的流媒体检测,基础信息检测适配MACOS系统 2025-06-28 13:50:54 +00:00
spiritlhl
db88ee8479 fix: 添加sysbench的天梯图: https://sysbench.spiritlhl.net/ 2025-06-15 12:44:45 +00:00
spiritlhl
67a3bfdaad fix: 修复自动更新安装版本中的版本提取代码 2025-06-05 20:45:51 +08:00
spiritlhl
e57ce05c0c fix: 回退修改 2025-06-05 20:39:52 +08:00
spiritlhl
62137f0bb1 fix: 修复仅安装本体时,可能宿主机连curl/unzip都没有的问他 2025-06-05 20:38:56 +08:00
spiritlhl
f9d8c9ee4c fix: 修复step匹配规则 2025-06-03 23:19:46 +08:00
15 changed files with 847 additions and 508 deletions

View File

@@ -42,23 +42,32 @@ jobs:
GOPRIVATE: github.com/oneclickvirt/security GOPRIVATE: github.com/oneclickvirt/security
- name: Update goecs.sh with new version - name: Update goecs.sh with new version
if: startsWith(github.ref, 'refs/tags/v')
run: | run: |
VERSION="${GITHUB_REF#refs/tags/v}" if [[ "$GITHUB_REF" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.1.37")
fi
echo "Using version: $VERSION"
FILE="goecs.sh" FILE="goecs.sh"
BRANCH="master" BRANCH="master"
# Checkout master branch git config --global user.name "github-actions[bot]"
git fetch origin $BRANCH:$BRANCH git config --global user.email "github-actions[bot]@users.noreply.github.com"
git switch $BRANCH git config --global --unset url."git@github.com:".insteadOf || true
# Replace version in goecs.sh git fetch origin $BRANCH
git checkout $BRANCH
if [ ! -f "$FILE" ]; then
echo "Error: $FILE not found"
exit 1
fi
sed -i "s/\(_yellow \"Unable to get version info, using default version \).*\(\".*\)/\1$VERSION\2/" "$FILE" sed -i "s/\(_yellow \"Unable to get version info, using default version \).*\(\".*\)/\1$VERSION\2/" "$FILE"
sed -i "s/\(ECS_VERSION=\"\).*\(\"\)/\1$VERSION\2/" "$FILE" sed -i "s/\(ECS_VERSION=\"\).*\(\"\)/\1$VERSION\2/" "$FILE"
# Commit and push if git diff --quiet "$FILE"; then
git config user.name "github-actions" echo "No changes detected in $FILE"
git config user.email "github-actions@github.com" exit 0
fi
git add "$FILE" git add "$FILE"
git commit -m "chore: update ECS_VERSION to $VERSION in goecs.sh" git commit -m "chore: update ECS_VERSION to $VERSION in goecs.sh"
git push origin $BRANCH git push origin $BRANCH
env: env:
GITHUB_TOKEN: ${{ secrets.GHT }} GITHUB_TOKEN: ${{ secrets.GHT }}

View File

@@ -6,7 +6,9 @@ builds:
env: env:
- CGO_ENABLED=0 - CGO_ENABLED=0
ldflags: ldflags:
- -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0 - -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0 -extldflags=-static
flags:
- -trimpath
goos: goos:
- linux - linux
- windows - windows
@@ -34,6 +36,8 @@ builds:
- CXX=o64-clang++ - CXX=o64-clang++
ldflags: ldflags:
- -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0 - -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0
flags:
- -trimpath
goos: goos:
- darwin - darwin
goarch: goarch:
@@ -47,6 +51,8 @@ builds:
- CXX=oa64-clang++ - CXX=oa64-clang++
ldflags: ldflags:
- -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0 - -s -w -X main.version={{.Version}} -X main.arch={{.Arch}} -checklinkname=0
flags:
- -trimpath
goos: goos:
- darwin - darwin
goarch: goarch:
@@ -75,4 +81,4 @@ changelog:
- Merge pull request - Merge pull request
- Merge branch - Merge branch
- go mod tidy - go mod tidy
- New translations - New translations

View File

@@ -1,6 +1,8 @@
# ECS # ECS
[![release](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml/badge.svg)](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml) [![release](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml/badge.svg)](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Foneclickvirt%2Fecs.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Foneclickvirt%2Fecs?ref=badge_shield)
[![Hits](https://hits.spiritlhl.net/goecs.svg?action=hit&title=Hits&title_bg=%23555555&count_bg=%230eecf8&edge_flat=false)](https://hits.spiritlhl.net) [![Hits](https://hits.spiritlhl.net/goecs.svg?action=hit&title=Hits&title_bg=%23555555&count_bg=%230eecf8&edge_flat=false)](https://hits.spiritlhl.net)
@@ -137,19 +139,19 @@ Shell 版本:[https://github.com/spiritLHLS/ecs](https://github.com/spiritLHLS
export noninteractive=true && ./goecs.sh env export noninteractive=true && ./goecs.sh env
``` ```
3. **安装 `goecs`** 3. **安装 `goecs` 本体(仅下载二进制文件无依赖安装)**
```bash ```bash
./goecs.sh install ./goecs.sh install
``` ```
4. **升级 `goecs`** 4. **升级 `goecs` 本体**
```bash ```bash
./goecs.sh upgrade ./goecs.sh upgrade
``` ```
5. **卸载 `goecs`** 5. **卸载 `goecs` 本体**
```bash ```bash
./goecs.sh uninstall ./goecs.sh uninstall
@@ -341,6 +343,7 @@ GOOS=darwin GOARCH=amd64 go build -o goecs_darwin
| 测试稳定性 | 核心测试组件10年以上未变 | 每个大版本更新测试项,分数不同版本间难以对比(每个版本对标当前最好的CPU) | | 测试稳定性 | 核心测试组件10年以上未变 | 每个大版本更新测试项,分数不同版本间难以对比(每个版本对标当前最好的CPU) |
| 测试内容 | 仅测试计算性能 | 覆盖多种性能测试,分数加权计算,但部分测试实际不常用 | | 测试内容 | 仅测试计算性能 | 覆盖多种性能测试,分数加权计算,但部分测试实际不常用 |
| 适用场景 | 适合快速测试,仅测试计算性能 | 适合综合全面的测试 | | 适用场景 | 适合快速测试,仅测试计算性能 | 适合综合全面的测试 |
| 排行榜 | [sysbench.spiritlhl.net](https://sysbench.spiritlhl.net/) | [browser.geekbench.com](https://browser.geekbench.com/) |
且```goecs```测试使用何种CPU测试方式可使用参数指定默认只是为了更多用户快速测试的需求 且```goecs```测试使用何种CPU测试方式可使用参数指定默认只是为了更多用户快速测试的需求
@@ -371,7 +374,7 @@ GOOS=darwin GOARCH=amd64 go build -o goecs_darwin
感谢 感谢
<a href="https://h501.io/?from=69" target="_blank"> <a href="https://h501.io/?from=69" target="_blank">
<img src="https://github.com/spiritLHLS/ecs/assets/103393591/dfd47230-2747-4112-be69-b5636b34f07f" alt="h501"> <img src="https://github.com/spiritLHLS/ecs/assets/103393591/dfd47230-2747-4112-be69-b5636b34f07f" alt="h501" style="height: 50px;">
</a> </a>
提供的免费托管支持本开源项目的共享测试结果存储 提供的免费托管支持本开源项目的共享测试结果存储
@@ -379,13 +382,20 @@ GOOS=darwin GOARCH=amd64 go build -o goecs_darwin
同时感谢以下平台提供编辑和测试支持 同时感谢以下平台提供编辑和测试支持
<a href="https://www.jetbrains.com/go/" target="_blank"> <a href="https://www.jetbrains.com/go/" target="_blank">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/GoLand.png" alt="goland"> <img src="https://resources.jetbrains.com/storage/products/company/brand/logos/GoLand.png" alt="goland" style="height: 50px;">
</a> </a>
<a href="https://community.ibm.com/zsystems/form/l1cc-oss-vm-request/" target="_blank"> <a href="https://community.ibm.com/zsystems/form/l1cc-oss-vm-request/" target="_blank">
<img src="https://linuxone.cloud.marist.edu/oss/resources/images/linuxonelogo03.png" alt="ibm"> <img src="https://linuxone.cloud.marist.edu/oss/resources/images/linuxonelogo03.png" alt="ibm" style="height: 50px;">
</a>
<a href="https://console.zmto.com/?affid=1524" target="_blank">
<img src="https://console.zmto.com/templates/2019/dist/images/logo_dark.svg" alt="zmto" style="height: 50px;">
</a> </a>
## Stargazers over time ## Stargazers over time
[![Stargazers over time](https://starchart.cc/oneclickvirt/ecs.svg?variant=adaptive)](https://starchart.cc/oneclickvirt/ecs) [![Stargazers over time](https://starchart.cc/oneclickvirt/ecs.svg?variant=adaptive)](https://www.spiritlhl.net)
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Foneclickvirt%2Fecs.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Foneclickvirt%2Fecs?ref=badge_large)

View File

@@ -368,7 +368,7 @@ Thank [he.net](https://he.net) [bgp.tools](https://bgp.tools) [ipinfo.io](https:
Thank Thank
<a href="https://h501.io/?from=69" target="_blank"> <a href="https://h501.io/?from=69" target="_blank">
<img src="https://github.com/spiritLHLS/ecs/assets/103393591/dfd47230-2747-4112-be69-b5636b34f07f" alt="h501"> <img src="https://github.com/spiritLHLS/ecs/assets/103393591/dfd47230-2747-4112-be69-b5636b34f07f" alt="h501" style="height: 50px;">
</a> </a>
provided free hosting support for this open source project's shared test results storage provided free hosting support for this open source project's shared test results storage
@@ -376,13 +376,17 @@ provided free hosting support for this open source project's shared test results
Thanks also to the following platforms for editorial and testing support Thanks also to the following platforms for editorial and testing support
<a href="https://www.jetbrains.com/go/" target="_blank"> <a href="https://www.jetbrains.com/go/" target="_blank">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/GoLand.png" alt="goland"> <img src="https://resources.jetbrains.com/storage/products/company/brand/logos/GoLand.png" alt="goland" style="height: 50px;">
</a> </a>
<a href="https://community.ibm.com/zsystems/form/l1cc-oss-vm-request/" target="_blank"> <a href="https://community.ibm.com/zsystems/form/l1cc-oss-vm-request/" target="_blank">
<img src="https://linuxone.cloud.marist.edu/oss/resources/images/linuxonelogo03.png" alt="ibm"> <img src="https://linuxone.cloud.marist.edu/oss/resources/images/linuxonelogo03.png" alt="ibm" style="height: 50px;">
</a>
<a href="https://console.zmto.com/?affid=1524" target="_blank">
<img src="https://console.zmto.com/templates/2019/dist/images/logo_dark.svg" alt="zmto" style="height: 50px;">
</a> </a>
## Stargazers over time ## Stargazers over time
[![Stargazers over time](https://starchart.cc/oneclickvirt/ecs.svg?variant=adaptive)](https://starchart.cc/oneclickvirt/ecs) [![Stargazers over time](https://starchart.cc/oneclickvirt/ecs.svg?variant=adaptive)](https://www.spiritlhl.net)

View File

@@ -110,6 +110,8 @@ AMD的7950x单核满血性能得分在6500左右AMD的5950x单核满血性能
有时候多核得分和单核得分一样证明商家在限制程序并发使用CPU典型例子腾讯云。 有时候多核得分和单核得分一样证明商家在限制程序并发使用CPU典型例子腾讯云。
```Sysbench```的基准可见 [CPU Performance Ladder For Sysbench](https://sysbench.spiritlhl.net/) 天梯图具体得分不分测试的sysbench的版本。
```GeekBench```的基准可见 [官方网站](https://browser.geekbench.com/processor-benchmarks/) 天梯图,具体得分每个```GeekBench```版本都不一样,注意使用时测试的```GeekBench```版本是什么。 ```GeekBench```的基准可见 [官方网站](https://browser.geekbench.com/processor-benchmarks/) 天梯图,具体得分每个```GeekBench```版本都不一样,注意使用时测试的```GeekBench```版本是什么。
多说一句,```GeekBench```测的很多内容,实际在服务器使用过程中根本用不到,测试仅供参考。当然```Sysbench```非常不全面但它基于最基础的计算性能可以大致比较CPU的性能。 多说一句,```GeekBench```测的很多内容,实际在服务器使用过程中根本用不到,测试仅供参考。当然```Sysbench```非常不全面但它基于最基础的计算性能可以大致比较CPU的性能。
@@ -279,6 +281,8 @@ AMD's 7950x single-core full performance score is around 6500, AMD's 5950x singl
Sometimes multi-core scores are the same as single-core scores, proving that the vendor is limiting program concurrent use of CPU, a typical example being Tencent Cloud. Sometimes multi-core scores are the same as single-core scores, proving that the vendor is limiting program concurrent use of CPU, a typical example being Tencent Cloud.
Benchmarks for ```Sysbench`` can be found in the [CPU Performance Ladder For Sysbench](https://sysbench.spiritlhl.net/) ladder chart, with specific scores regardless of the version of sysbench tested.
For `GeekBench` baselines, see the [official website](https://browser.geekbench.com/processor-benchmarks/) ladder chart. Specific scores differ for each `GeekBench` version, so note which `GeekBench` version is being used when testing. For `GeekBench` baselines, see the [official website](https://browser.geekbench.com/processor-benchmarks/) ladder chart. Specific scores differ for each `GeekBench` version, so note which `GeekBench` version is being used when testing.
As an additional note, many things tested by `GeekBench` are not actually used in server usage processes, so the test is for reference only. Of course, `Sysbench` is very incomplete, but it can roughly compare CPU performance based on the most basic computational performance. As an additional note, many things tested by `GeekBench` are not actually used in server usage processes, so the test is for reference only. Of course, `Sysbench` is very incomplete, but it can roughly compare CPU performance based on the most basic computational performance.
@@ -424,6 +428,8 @@ AMDの7950xシングルコアのフルパフォーマンススコアは約6500
時々、マルチコアスコアとシングルコアスコアが同じ場合があります。これは販売者がプログラムの並列CPU使用を制限していることを示しています。典型的な例はTencent Cloudです。 時々、マルチコアスコアとシングルコアスコアが同じ場合があります。これは販売者がプログラムの並列CPU使用を制限していることを示しています。典型的な例はTencent Cloudです。
Sysbenchのベンチマークは[CPU Performance Ladder For Sysbench](https://sysbench.spiritlhl.net/)のラダーチャートで見ることができる。
```GeekBench```の基準は[公式ウェブサイト](https://browser.geekbench.com/processor-benchmarks/)の階層チャートを参照してください。具体的なスコアは各```GeekBench```バージョンで異なるため、テスト時の```GeekBench```バージョンに注意してください。 ```GeekBench```の基準は[公式ウェブサイト](https://browser.geekbench.com/processor-benchmarks/)の階層チャートを参照してください。具体的なスコアは各```GeekBench```バージョンで異なるため、テスト時の```GeekBench```バージョンに注意してください。
補足ですが、```GeekBench```がテストする多くの内容は、サーバー使用過程で実際には必要ないことが多いです。テストは参考程度にしてください。もちろん```Sysbench```は非常に包括的ではありませんが、基本的な計算性能に基づいてCPUのパフォーマンスを大まかに比較できます。 補足ですが、```GeekBench```がテストする多くの内容は、サーバー使用過程で実際には必要ないことが多いです。テストは参考程度にしてください。もちろん```Sysbench```は非常に包括的ではありませんが、基本的な計算性能に基づいてCPUのパフォーマンスを大まかに比較できます。

View File

@@ -36,6 +36,6 @@ func DiskTest(language, testMethod, testPath string, isMultiCheck bool, autoChan
if !strings.Contains(res, "\n") && res != "" { if !strings.Contains(res, "\n") && res != "" {
res += "\n" res += "\n"
} }
fmt.Printf(res) fmt.Printf("%s", res)
//fmt.Println("--------------------------------------------------") //fmt.Println("--------------------------------------------------")
} }

View File

@@ -3,5 +3,5 @@ package disktest
import "testing" import "testing"
func TestDiskIoTest(t *testing.T) { func TestDiskIoTest(t *testing.T) {
DiskTest("zh", "sysbench", "", false) DiskTest("zh", "sysbench", "", false, false)
} }

8
go.mod
View File

@@ -7,9 +7,9 @@ toolchain go1.24.2
require ( require (
github.com/imroc/req/v3 v3.50.0 github.com/imroc/req/v3 v3.50.0
github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841 github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841
github.com/oneclickvirt/UnlockTests v0.0.26-20250329125926 github.com/oneclickvirt/UnlockTests v0.0.27-20250628125053
github.com/oneclickvirt/backtrace v0.0.5-20250517095024 github.com/oneclickvirt/backtrace v0.0.5-20250629024536
github.com/oneclickvirt/basics v0.0.12-20250521031609 github.com/oneclickvirt/basics v0.0.13-20250629023612
github.com/oneclickvirt/cputest v0.0.10-20250404151448 github.com/oneclickvirt/cputest v0.0.10-20250404151448
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 github.com/oneclickvirt/defaultset v0.0.2-20240624082446
github.com/oneclickvirt/disktest v0.0.8-20250425015826 github.com/oneclickvirt/disktest v0.0.8-20250425015826
@@ -18,7 +18,7 @@ require (
github.com/oneclickvirt/nt3 v0.0.5-20250416131047 github.com/oneclickvirt/nt3 v0.0.5-20250416131047
github.com/oneclickvirt/pingtest v0.0.7-20250413051539 github.com/oneclickvirt/pingtest v0.0.7-20250413051539
github.com/oneclickvirt/portchecker v0.0.3-20250329125750 github.com/oneclickvirt/portchecker v0.0.3-20250329125750
github.com/oneclickvirt/security v0.0.4-20250522031128 github.com/oneclickvirt/security v0.0.4-20250629033626
github.com/oneclickvirt/speedtest v0.0.9-20250521034111 github.com/oneclickvirt/speedtest v0.0.9-20250521034111
) )

16
go.sum
View File

@@ -99,12 +99,12 @@ github.com/nxtrace/NTrace-core v1.4.0 h1:pDN2BqxIYjedDKCDDOFBcDNOBnavGcx+4wbiG65
github.com/nxtrace/NTrace-core v1.4.0/go.mod h1:0AWqbqiIJbpbFG6W48vtJ6pWM8PPF+lQ1fi2371y+zA= github.com/nxtrace/NTrace-core v1.4.0/go.mod h1:0AWqbqiIJbpbFG6W48vtJ6pWM8PPF+lQ1fi2371y+zA=
github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841 h1:Zef93z9UiZQwRAKnnZYALmpBKvvuVaq34MEsuWwk6nc= github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841 h1:Zef93z9UiZQwRAKnnZYALmpBKvvuVaq34MEsuWwk6nc=
github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841/go.mod h1:DAmFPRjFV5p9fEzUUSml5jJGn2f1NZJQCzTxITHDjc4= github.com/oneclickvirt/CommonMediaTests v0.0.4-20250329123841/go.mod h1:DAmFPRjFV5p9fEzUUSml5jJGn2f1NZJQCzTxITHDjc4=
github.com/oneclickvirt/UnlockTests v0.0.26-20250329125926 h1:H5//xwVjDR02bQ1hLa3G7LnwccsudPMjBVt7WCx2y/U= github.com/oneclickvirt/UnlockTests v0.0.27-20250628125053 h1:Ug8kySZR1weRUcsnGOv+f3HAl791AfkA7EWV3JmiMQA=
github.com/oneclickvirt/UnlockTests v0.0.26-20250329125926/go.mod h1:yXWIZB6iLS88pEd9m4QJi1GENn+7I91zA72y5ONz2Oc= github.com/oneclickvirt/UnlockTests v0.0.27-20250628125053/go.mod h1:yXWIZB6iLS88pEd9m4QJi1GENn+7I91zA72y5ONz2Oc=
github.com/oneclickvirt/backtrace v0.0.5-20250517095024 h1:j912aga/17znOqMB2VAxWOQYa4GL6YMFBhv+6c7jkvA= github.com/oneclickvirt/backtrace v0.0.5-20250629024536 h1:caHCa0DHmbYWBFN1bqKxpvPnN0wOxDEqJv1VDvDdLWs=
github.com/oneclickvirt/backtrace v0.0.5-20250517095024/go.mod h1:5AH00bo41hH3d2/JVuCTlBkZUs3AXX4nlKVXb6piZcI= github.com/oneclickvirt/backtrace v0.0.5-20250629024536/go.mod h1:5AH00bo41hH3d2/JVuCTlBkZUs3AXX4nlKVXb6piZcI=
github.com/oneclickvirt/basics v0.0.12-20250521031609 h1:3WxHe+jKrZHF81oa8Xk3IgHCRqTC5GDjv8alR0geamU= github.com/oneclickvirt/basics v0.0.13-20250629023612 h1:cQg+cGBt2NMRrjhJPH+CbevZrwtMU8pIZIY2Lp6zmt4=
github.com/oneclickvirt/basics v0.0.12-20250521031609/go.mod h1:yN1IEOXN6v/GJqJSA70Pooo6nXBI/6rq72vTY72wJMQ= github.com/oneclickvirt/basics v0.0.13-20250629023612/go.mod h1:yN1IEOXN6v/GJqJSA70Pooo6nXBI/6rq72vTY72wJMQ=
github.com/oneclickvirt/cputest v0.0.10-20250404151448 h1:ovGtCwFXG0qmpyNDRqcNDIiAmhrtemCjIUXTJ1fPH0o= github.com/oneclickvirt/cputest v0.0.10-20250404151448 h1:ovGtCwFXG0qmpyNDRqcNDIiAmhrtemCjIUXTJ1fPH0o=
github.com/oneclickvirt/cputest v0.0.10-20250404151448/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY= github.com/oneclickvirt/cputest v0.0.10-20250404151448/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY=
github.com/oneclickvirt/dd v0.0.1-20250406062523 h1:jegTww4fuoFEqwFozvGJEqUNI/5ew3QJ0XcKZZ/zuTs= github.com/oneclickvirt/dd v0.0.1-20250406062523 h1:jegTww4fuoFEqwFozvGJEqUNI/5ew3QJ0XcKZZ/zuTs=
@@ -125,8 +125,8 @@ github.com/oneclickvirt/pingtest v0.0.7-20250413051539 h1:mYOsEmMtwKr40hwM2NimVL
github.com/oneclickvirt/pingtest v0.0.7-20250413051539/go.mod h1:d3Ntx5m9lMll3a/k3+2B+5emj//vgDh4/NHTxs2qQE8= github.com/oneclickvirt/pingtest v0.0.7-20250413051539/go.mod h1:d3Ntx5m9lMll3a/k3+2B+5emj//vgDh4/NHTxs2qQE8=
github.com/oneclickvirt/portchecker v0.0.3-20250329125750 h1:TTNL0pnQlRsn046kW59I/9UWRpihttFHWnU7Ixycggk= github.com/oneclickvirt/portchecker v0.0.3-20250329125750 h1:TTNL0pnQlRsn046kW59I/9UWRpihttFHWnU7Ixycggk=
github.com/oneclickvirt/portchecker v0.0.3-20250329125750/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k= github.com/oneclickvirt/portchecker v0.0.3-20250329125750/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
github.com/oneclickvirt/security v0.0.4-20250522031128 h1:k/zpiES/W0lW6Rumlmo4i7zp2ncimfeOUKadrylde8M= github.com/oneclickvirt/security v0.0.4-20250629033626 h1:DEchQ7WKKz4CzQpMlweoqA993BGncvmp1rL1ICNDJ2g=
github.com/oneclickvirt/security v0.0.4-20250522031128/go.mod h1:hdCr9UFkJ0tQfFP4mIycZehF5v7VfzSQwNn2qkY0bGo= github.com/oneclickvirt/security v0.0.4-20250629033626/go.mod h1:/5eVnZLvP7RUjwhoI6d8iIMP7msbkHC5So3ZxM+A7Zg=
github.com/oneclickvirt/speedtest v0.0.9-20250521034111 h1:yygDk+s5qFhPMDRzdMfyopm1xU512peNqY6WYyvYcfY= github.com/oneclickvirt/speedtest v0.0.9-20250521034111 h1:yygDk+s5qFhPMDRzdMfyopm1xU512peNqY6WYyvYcfY=
github.com/oneclickvirt/speedtest v0.0.9-20250521034111/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI= github.com/oneclickvirt/speedtest v0.0.9-20250521034111/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI=
github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM= github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM=

967
goecs.go

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# From https://github.com/oneclickvirt/ecs # From https://github.com/oneclickvirt/ecs
# 2025.04.07 # 2025.06.05
# curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh # curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh
# 或 # 或
@@ -119,13 +119,31 @@ cleanup_epel() {
} }
goecs_check() { goecs_check() {
# Get system and architecture info with error handling if command -v apt-get >/dev/null 2>&1; then
INSTALL_CMD="apt-get -y install"
elif command -v yum >/dev/null 2>&1; then
INSTALL_CMD="yum -y install"
elif command -v dnf >/dev/null 2>&1; then
INSTALL_CMD="dnf -y install"
elif command -v pacman >/dev/null 2>&1; then
INSTALL_CMD="pacman -S --noconfirm"
elif command -v apk >/dev/null 2>&1; then
INSTALL_CMD="apk add"
elif command -v zypper >/dev/null 2>&1; then
INSTALL_CMD="zypper install -y"
fi
if ! command -v unzip >/dev/null 2>&1; then
_green "Installing unzip"
${INSTALL_CMD} unzip
fi
if ! command -v curl >/dev/null 2>&1; then
_green "Installing curl"
${INSTALL_CMD} curl
fi
os=$(uname -s 2>/dev/null || echo "Unknown") os=$(uname -s 2>/dev/null || echo "Unknown")
arch=$(uname -m 2>/dev/null || echo "Unknown") arch=$(uname -m 2>/dev/null || echo "Unknown")
# First check for China IP
check_china check_china
# Get latest version number with multiple backup sources ECS_VERSION="0.1.37"
ECS_VERSION=""
for api in \ for api in \
"https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \ "https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \
"https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \ "https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \
@@ -137,10 +155,9 @@ goecs_check() {
sleep 1 sleep 1
done done
if [ -z "$ECS_VERSION" ]; then if [ -z "$ECS_VERSION" ]; then
_yellow "Unable to get version info, using default version 0.1.33" _yellow "Unable to get version info, using default version 0.1.37"
ECS_VERSION="0.1.33" ECS_VERSION="0.1.37"
fi fi
# Check if original goecs command exists
version_output="" version_output=""
for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do
if [ -x "$(command -v $cmd_path 2>/dev/null)" ]; then if [ -x "$(command -v $cmd_path 2>/dev/null)" ]; then
@@ -164,7 +181,6 @@ goecs_check() {
_green "goecs not found, installation needed, starting in 5 seconds" _green "goecs not found, installation needed, starting in 5 seconds"
fi fi
sleep 5 sleep 5
# Download corresponding version with error handling
if [[ "$CN" == true ]]; then if [[ "$CN" == true ]]; then
_yellow "Using China mirror for download..." _yellow "Using China mirror for download..."
base_url="https://cnb.cool/oneclickvirt/ecs/-/git/raw/main" base_url="https://cnb.cool/oneclickvirt/ecs/-/git/raw/main"
@@ -177,7 +193,6 @@ goecs_check() {
base_url="https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}" base_url="https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}"
fi fi
fi fi
# Build download URL with architecture support
local zip_file="" local zip_file=""
case $os in case $os in
Linux|linux|LINUX) Linux|linux|LINUX)
@@ -215,7 +230,6 @@ goecs_check() {
esac esac
download_url="${base_url}/${zip_file}" download_url="${base_url}/${zip_file}"
_green "Downloading $download_url" _green "Downloading $download_url"
# Download file with retry mechanism
local max_retries=3 local max_retries=3
local retry_count=0 local retry_count=0
while [ $retry_count -lt $max_retries ]; do while [ $retry_count -lt $max_retries ]; do
@@ -230,29 +244,11 @@ goecs_check() {
_red "Download failed, please check your network connection or download manually" _red "Download failed, please check your network connection or download manually"
return 1 return 1
fi fi
if ! command -v unzip >/dev/null 2>&1; then
_green "Installing $cmd"
if command -v apt-get >/dev/null 2>&1; then
INSTALL_CMD="apt-get -y install"
elif command -v yum >/dev/null 2>&1; then
INSTALL_CMD="yum -y install"
elif command -v dnf >/dev/null 2>&1; then
INSTALL_CMD="dnf -y install"
elif command -v pacman >/dev/null 2>&1; then
INSTALL_CMD="pacman -S --noconfirm"
elif command -v apk >/dev/null 2>&1; then
INSTALL_CMD="apk add"
elif command -v zypper >/dev/null 2>&1; then
INSTALL_CMD="zypper install -y"
fi
${INSTALL_CMD} "$cmd"
fi
if ! unzip -o goecs.zip >/dev/null 2>&1; then if ! unzip -o goecs.zip >/dev/null 2>&1; then
_red "Extraction failed" _red "Extraction failed"
return 1 return 1
fi fi
rm -f goecs.zip README.md LICENSE README_EN.md rm -f goecs.zip README.md LICENSE README_EN.md
# Set execution permissions and install
chmod 777 goecs chmod 777 goecs
for install_path in "/usr/bin" "/usr/local/bin"; do for install_path in "/usr/bin" "/usr/local/bin"; do
if [ -d "$install_path" ]; then if [ -d "$install_path" ]; then
@@ -260,7 +256,6 @@ goecs_check() {
break break
fi fi
done done
# Set system parameters
if [ "$os" != "Darwin" ]; then if [ "$os" != "Darwin" ]; then
PARAM="net.ipv4.ping_group_range" PARAM="net.ipv4.ping_group_range"
NEW_VALUE="0 2147483647" NEW_VALUE="0 2147483647"
@@ -273,7 +268,6 @@ goecs_check() {
sysctl -p >/dev/null 2>&1 sysctl -p >/dev/null 2>&1
fi fi
fi fi
# Set special permissions
setcap cap_net_raw=+ep goecs 2>/dev/null setcap cap_net_raw=+ep goecs 2>/dev/null
setcap cap_net_raw=+ep /usr/bin/goecs 2>/dev/null setcap cap_net_raw=+ep /usr/bin/goecs 2>/dev/null
setcap cap_net_raw=+ep /usr/local/bin/goecs 2>/dev/null setcap cap_net_raw=+ep /usr/local/bin/goecs 2>/dev/null
@@ -320,15 +314,15 @@ InstallSysbench() {
fi fi
fi fi
case "$Var_OSRelease" in case "$Var_OSRelease" in
ubuntu | debian | astra) ubuntu | debian | astra)
! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;; ! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;;
centos | rhel | almalinux | redhat | opencloudos) centos | rhel | almalinux | redhat | opencloudos)
(yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;; (yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;;
fedora) fedora)
dnf -y install sysbench ;; dnf -y install sysbench ;;
arch) arch)
pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;; pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;;
freebsd) freebsd)
pkg install -y sysbench ;; pkg install -y sysbench ;;
alpinelinux) alpinelinux)
if [ "$noninteractive" != "true" ]; then if [ "$noninteractive" != "true" ]; then
@@ -359,7 +353,7 @@ InstallSysbench() {
echo -e "${Msg_Success}Sysbench installed successfully." echo -e "${Msg_Success}Sysbench installed successfully."
fi fi
fi ;; fi ;;
*) *)
_red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;; _red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;;
esac esac
if [[ $SYSTEM =~ ^(CentOS|RHEL|AlmaLinux)$ ]]; then if [[ $SYSTEM =~ ^(CentOS|RHEL|AlmaLinux)$ ]]; then
@@ -442,7 +436,6 @@ env_check() {
PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add --no-cache" "pkg_add -I" "yum -y install") PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add --no-cache" "pkg_add -I" "yum -y install")
PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "pkg_delete -I" "yum -y remove") PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "pkg_delete -I" "yum -y remove")
PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "pkg_delete -a" "yum -y autoremove") PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "pkg_delete -a" "yum -y autoremove")
# Check system information
if [ -f /etc/opencloudos-release ]; then if [ -f /etc/opencloudos-release ]; then
SYS="opencloudos" SYS="opencloudos"
elif [ -s /etc/os-release ]; then elif [ -s /etc/os-release ]; then
@@ -460,7 +453,6 @@ env_check() {
else else
SYS="$(uname -s)" SYS="$(uname -s)"
fi fi
# Match operating system
SYSTEM="" SYSTEM=""
for ((int = 0; int < ${#REGEX[@]}; int++)); do for ((int = 0; int < ${#REGEX[@]}; int++)); do
if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then
@@ -472,7 +464,6 @@ env_check() {
break break
fi fi
done done
# If system is unrecognized, try common package managers
if [ -z "$SYSTEM" ]; then if [ -z "$SYSTEM" ]; then
_yellow "Unable to recognize system, trying common package managers..." _yellow "Unable to recognize system, trying common package managers..."
if command -v apt-get >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then
@@ -539,14 +530,12 @@ env_check() {
fi fi
fi fi
fi fi
# Install necessary commands
for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do
if ! command -v "$cmd" >/dev/null 2>&1; then if ! command -v "$cmd" >/dev/null 2>&1; then
_green "Installing $cmd" _green "Installing $cmd"
${INSTALL_CMD} "$cmd" ${INSTALL_CMD} "$cmd"
fi fi
done done
# sysbench installation
if ! command -v sysbench >/dev/null 2>&1; then if ! command -v sysbench >/dev/null 2>&1; then
_green "Installing sysbench" _green "Installing sysbench"
${INSTALL_CMD} sysbench ${INSTALL_CMD} sysbench
@@ -561,7 +550,6 @@ env_check() {
Check_SysBench Check_SysBench
fi fi
fi fi
# geekbench and speedtest installation
if ! command -v geekbench >/dev/null 2>&1; then if ! command -v geekbench >/dev/null 2>&1; then
_green "Installing geekbench" _green "Installing geekbench"
curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/cputest/main/dgb.sh" -o dgb.sh && chmod +x dgb.sh curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/cputest/main/dgb.sh" -o dgb.sh && chmod +x dgb.sh
@@ -580,7 +568,6 @@ env_check() {
${INSTALL_CMD} iputils-ping >/dev/null 2>&1 ${INSTALL_CMD} iputils-ping >/dev/null 2>&1
${INSTALL_CMD} ping >/dev/null 2>&1 ${INSTALL_CMD} ping >/dev/null 2>&1
fi fi
# MacOS support
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
echo "Detected MacOS, installing sysbench iproute2mac..." echo "Detected MacOS, installing sysbench iproute2mac..."
brew install --force sysbench iproute2mac brew install --force sysbench iproute2mac
@@ -616,7 +603,7 @@ show_help() {
3. 关键服务失败 3. 关键服务失败
推荐: 推荐:
环境依赖安装过程中挂起执行 环境依赖安装过程中挂起执行
可选组件: 可选组件:
sysbench/geekbench (CPU性能测试) sysbench/geekbench (CPU性能测试)
sudo, tar, unzip, dd, fio sudo, tar, unzip, dd, fio
@@ -643,7 +630,7 @@ Available commands:
3. Critical service failures 3. Critical service failures
Recommended: Recommended:
Hanging execution during environment dependency installation Hanging execution during environment dependency installation
Optional components: Optional components:
sysbench/geekbench (CPU testing) sysbench/geekbench (CPU testing)
sudo, tar, unzip, dd, fio sudo, tar, unzip, dd, fio
@@ -677,4 +664,3 @@ case "$1" in
show_help show_help
;; ;;
esac esac

View File

@@ -31,5 +31,5 @@ func MemoryTest(language, testMethod string) {
if !strings.Contains(res, "\n") && res != "" { if !strings.Contains(res, "\n") && res != "" {
res += "\n" res += "\n"
} }
fmt.Printf(res) fmt.Printf("%s", res)
} }

View File

@@ -6,5 +6,5 @@ import (
) )
func Test(t *testing.T) { func Test(t *testing.T) {
fmt.Printf(MediaTest("zh")) fmt.Printf("%s", MediaTest("zh"))
} }

View File

@@ -3,13 +3,11 @@ package utils
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"fmt" "fmt"
"github.com/imroc/req/v3"
"github.com/oneclickvirt/UnlockTests/uts"
"github.com/oneclickvirt/basics/system"
. "github.com/oneclickvirt/defaultset"
"github.com/oneclickvirt/security/network"
"io" "io"
"net"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -17,6 +15,12 @@ import (
"sync" "sync"
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/imroc/req/v3"
"github.com/oneclickvirt/UnlockTests/uts"
"github.com/oneclickvirt/basics/system"
. "github.com/oneclickvirt/defaultset"
"github.com/oneclickvirt/security/network"
) )
// PrintCenteredTitle 根据指定的宽度打印居中标题 // PrintCenteredTitle 根据指定的宽度打印居中标题
@@ -95,14 +99,14 @@ func CheckChina(enableLogger bool) bool {
} }
// BasicsAndSecurityCheck 执行安全检查 // BasicsAndSecurityCheck 执行安全检查
func BasicsAndSecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) { func BasicsAndSecurityCheck(language, nt3CheckType string, securityCheckStatus bool) (string, string, string) {
var wgt sync.WaitGroup var wgt sync.WaitGroup
var ipInfo, securityInfo, systemInfo string var ipInfo, securityInfo, systemInfo string
var err error var err error
wgt.Add(1) wgt.Add(1)
go func() { go func() {
defer wgt.Done() defer wgt.Done()
ipInfo, securityInfo, err = network.NetworkCheck("both", securtyCheckStatus, language) ipInfo, securityInfo, err = network.NetworkCheck("both", securityCheckStatus, language)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
@@ -330,3 +334,159 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) (string
} }
return "", "" return "", ""
} }
// ============================= 前置联网能力检测 =============================
var StackType string
type NetCheckResult struct {
HasIPv4 bool
HasIPv6 bool
Connected bool
StackType string // "IPv4", "IPv6", "DualStack", "None"
}
func makeResolver(proto, dnsAddr string) *net.Resolver {
return &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: 5 * time.Second,
}
return d.DialContext(ctx, proto, dnsAddr)
},
}
}
func CheckPublicAccess(timeout time.Duration) NetCheckResult {
if timeout < 2*time.Second {
timeout = 2 * time.Second
}
var wg sync.WaitGroup
resultChan := make(chan string, 8)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
checks := []struct {
Tag string
Addr string
Kind string // udp4, udp6, http4, http6
}{
// UDP DNS
{"IPv4", "223.5.5.5:53", "udp4"}, // 阿里 DNS
{"IPv4", "8.8.8.8:53", "udp4"}, // Google DNS
{"IPv6", "[2400:3200::1]:53", "udp6"}, // 阿里 IPv6 DNS
{"IPv6", "[2001:4860:4860::8888]:53", "udp6"}, // Google IPv6 DNS
// HTTP HEAD
{"IPv4", "https://www.baidu.com", "http4"}, // 百度
{"IPv4", "https://1.1.1.1", "http4"}, // Cloudflare
{"IPv6", "https://[2400:3200::1]", "http6"}, // 阿里 IPv6
{"IPv6", "https://[2606:4700::1111]", "http6"}, // Cloudflare IPv6
}
for _, check := range checks {
wg.Add(1)
go func(tag, addr, kind string) {
defer wg.Done()
defer func() {
if r := recover(); r != nil {
}
}()
switch kind {
case "udp4", "udp6":
dialer := &net.Dialer{
Timeout: timeout / 4,
}
conn, err := dialer.DialContext(ctx, kind, addr)
if err == nil && conn != nil {
conn.Close()
select {
case resultChan <- tag:
case <-ctx.Done():
return
}
}
case "http4", "http6":
var resolver *net.Resolver
if kind == "http4" {
resolver = makeResolver("udp4", "223.5.5.5:53")
} else {
resolver = makeResolver("udp6", "[2400:3200::1]:53")
}
dialer := &net.Dialer{
Timeout: timeout / 4,
Resolver: resolver,
}
transport := &http.Transport{
DialContext: dialer.DialContext,
MaxIdleConns: 1,
MaxIdleConnsPerHost: 1,
IdleConnTimeout: time.Second,
TLSHandshakeTimeout: timeout / 4,
ResponseHeaderTimeout: timeout / 4,
DisableKeepAlives: true,
}
client := &http.Client{
Timeout: timeout / 4,
Transport: transport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
req, err := http.NewRequestWithContext(ctx, "HEAD", addr, nil)
if err != nil {
return
}
resp, err := client.Do(req)
if err == nil && resp != nil {
if resp.Body != nil {
resp.Body.Close()
}
if resp.StatusCode < 500 {
select {
case resultChan <- tag:
case <-ctx.Done():
return
}
}
}
}
}(check.Tag, check.Addr, check.Kind)
}
go func() {
wg.Wait()
close(resultChan)
}()
hasV4 := false
hasV6 := false
for {
select {
case res, ok := <-resultChan:
if !ok {
goto result
}
if res == "IPv4" {
hasV4 = true
}
if res == "IPv6" {
hasV6 = true
}
case <-ctx.Done():
goto result
}
}
result:
stack := "None"
if hasV4 && hasV6 {
stack = "DualStack"
} else if hasV4 {
stack = "IPv4"
} else if hasV6 {
stack = "IPv6"
}
StackType = stack
return NetCheckResult{
HasIPv4: hasV4,
HasIPv6: hasV6,
Connected: hasV4 || hasV6,
StackType: stack,
}
}

17
utils/utils_test.go Normal file
View File

@@ -0,0 +1,17 @@
package utils
import (
"fmt"
"testing"
"time"
)
func TestCheckPublicAccess(t *testing.T) {
timeout := 3 * time.Second
result := CheckPublicAccess(timeout)
if result.Connected {
fmt.Printf("✅ 本机有公网连接,类型: %s\n", result.StackType)
} else {
fmt.Println("❌ 本机未检测到公网连接")
}
}