Skip to content

Commit 1e437aa

Browse files
committed
v0.0.1
1 parent d93eed9 commit 1e437aa

File tree

10 files changed

+843
-1
lines changed

10 files changed

+843
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
strategy:
9+
matrix:
10+
go: [ '1.22.x' ]
11+
os: [ ubuntu-latest ]
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Setup Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ${{ matrix.go }}
20+
- name: Test
21+
run: go test ./... -coverprofile=coverage.txt
22+
- name: Create Tag
23+
if: success() # 仅在测试成功时运行
24+
run: |
25+
git config --global user.name 'github-actions'
26+
git config --global user.email 'github-actions@github.com'
27+
TAG="v0.0.1-$(date +'%Y%m%d%H%M%S')"
28+
git tag $TAG
29+
git push origin $TAG
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Build and Release
2+
3+
on:
4+
# push:
5+
# branches: [ main ]
6+
# pull_request:
7+
# branches: [ main ]
8+
# release:
9+
# types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
name: Build and Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: 'stable'
24+
25+
- name: Test on Default Platform
26+
run: |
27+
go test -v ./...
28+
29+
- name: Delete Existing Release Assets
30+
run: |
31+
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/nt3/releases/tags/output" | jq -r '.id')
32+
echo "Deleting existing release assets..."
33+
assets=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/oneclickvirt/nt3/releases/$release_id/assets" | jq -r '.[] | .id')
34+
for asset in $assets; do
35+
echo "Deleting asset with ID: $asset"
36+
curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/nt3/releases/assets/$asset"
37+
done
38+
sleep 60
39+
40+
release-binary:
41+
name: Release Go Binary
42+
runs-on: ubuntu-latest
43+
needs: build
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v3
47+
48+
- name: Set up Go
49+
uses: actions/setup-go@v3
50+
with:
51+
go-version: 'stable'
52+
53+
- name: Build and Release
54+
run: |
55+
mkdir -p bin
56+
cd cmd
57+
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o ../bin/nt3-${{ matrix.goos }}-${{ matrix.goarch }} -v -ldflags="-extldflags=-static" .
58+
59+
- name: Upload New Assets
60+
run: |
61+
release_id=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/oneclickvirt/nt3/releases/tags/output" | jq -r '.id')
62+
echo "Uploading new assets to release..."
63+
for file in ./bin/*; do
64+
echo "Uploading $file to release..."
65+
curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
66+
-H "Content-Type: application/octet-stream" \
67+
--data-binary @"$file" \
68+
"https://uploads.github.com/repos/oneclickvirt/nt3/releases/$release_id/assets?name=$(basename "$file")"
69+
rm -rf $file
70+
done
71+
72+
strategy:
73+
matrix:
74+
goos: [windows, freebsd, linux, darwin]
75+
goarch: [amd64, 386]
76+
exclude:
77+
- goarch: 386
78+
goos: darwin
79+
include:
80+
- goos: windows
81+
goarch: 386
82+
- goos: windows
83+
goarch: amd64
84+
- goos: windows
85+
goarch: arm64
86+
- goos: darwin
87+
goarch: arm64
88+
- goos: linux
89+
goarch: arm
90+
goarm: 7
91+
- goos: linux
92+
goarch: arm64
93+
- goos: linux
94+
goarch: riscv64
95+
- goos: linux
96+
goarch: mips64
97+
- goos: linux
98+
goarch: mips64le
99+
- goos: linux
100+
goarch: mipsle
101+
- goos: linux
102+
goarch: mips
103+
- goos: freebsd
104+
goarch: arm64
105+
- goos: freebsd
106+
goarch: arm
107+
goarm: 7
108+
# - goos: linux
109+
# goarch: mipsle
110+
# gomips: softfloat
111+
# - goos: linux
112+
# goarch: mips
113+
# gomips: softfloat
114+
# - goos: linux
115+
# goarch: arm
116+
# goarm: 6
117+
# - goos: linux
118+
# goarch: arm
119+
# goarm: 5
120+
# - goos: linux
121+
# goarch: ppc64
122+
# - goos: linux
123+
# goarch: ppc64le
124+
# - goos: windows
125+
# goarch: arm
126+
# goarm: 7

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# nt3
1+
# nt3
2+
3+
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fnt3&count_bg=%232EFFF8&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) [![Build and Release](https://github.com/oneclickvirt/nt3/actions/workflows/main.yaml/badge.svg)](https://github.com/oneclickvirt/nt3/actions/workflows/main.yaml)
4+
5+
三网路由查询模块
6+
7+
## 说明
8+
9+
- [x] 使用[nexttrace](https://github.com/nxtrace/NTrace-core)进行ICMP测试,预先加载定义好的广州、上海、北京、成都的三网地址
10+
- [x] 支持双语输出,以```-l```指定```zh``````en```可指定输出的语言,未指定时默认使用中文输出
11+
- [x] 全平台编译支持(除了WIN)
12+
13+
## 使用
14+
15+
下载及安装
16+
17+
```
18+
curl https://raw.githubusercontent.com/oneclickvirt/nt3/main/nt3_install.sh -sSf | bash
19+
```
20+
21+
22+
23+
```
24+
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/nt3/main/nt3_install.sh -sSf | bash
25+
```
26+
27+
使用
28+
29+
```
30+
nt3
31+
```
32+
33+
34+
35+
```
36+
./nt3
37+
```
38+
39+
进行测试
40+
41+
无环境依赖,理论上适配所有系统和主流架构,更多架构请查看 https://github.com/oneclickvirt/nt3/releases/tag/output
42+
43+
```
44+
45+
```
46+
47+
## 在Golang中使用
48+
49+
```
50+
go get github.com/oneclickvirt/nt3@latest
51+
```
52+
53+
## Thanks
54+
55+
https://github.com/nxtrace/NTrace-core

cmd/main.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"net/http"
7+
"strings"
8+
9+
"github.com/oneclickvirt/nt3/model"
10+
"github.com/oneclickvirt/nt3/nt"
11+
)
12+
13+
func main() {
14+
go func() {
15+
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fnt3&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false")
16+
}()
17+
fmt.Println("项目地址:", "https://github.com/oneclickvirt/nt3")
18+
var showVersion bool
19+
var language, checkType, location string
20+
flag.BoolVar(&showVersion, "v", false, "Show version information")
21+
flag.StringVar(&language, "l", "", "Specify language parameter (en or zh, default is zh)")
22+
flag.StringVar(&checkType, "c", "", "Specify check type (both, ipv4, or ipv6, default is ipv4)")
23+
flag.StringVar(&location, "loc", "", "Specify location (supports GZ, BJ, SH, CD; corresponding to Guangzhou, Beijing, Shanghai, Chengdu)")
24+
// flag.BoolVar(&model.EnableLoger, "log", false, "Enable logging")
25+
flag.Parse()
26+
if showVersion {
27+
fmt.Println(model.NextTraceVersion)
28+
return
29+
}
30+
if language == "" {
31+
language = "zh"
32+
} else {
33+
language = strings.ToLower(language)
34+
}
35+
if checkType == "" || checkType == "ipv4" {
36+
checkType = "ipv4"
37+
} else if strings.ToLower(checkType) == "both" {
38+
checkType = "both"
39+
} else if strings.ToLower(checkType) == "ipv6" {
40+
checkType = "ipv6"
41+
}
42+
nt.TraceRoute(language, location, checkType)
43+
}

cmd/main_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "testing"
4+
5+
func Test(t *testing.T) {
6+
main()
7+
}

go.mod

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module github.com/oneclickvirt/nt3
2+
3+
go 1.22.4
4+
5+
require (
6+
github.com/fatih/color v1.17.0
7+
github.com/nxtrace/NTrace-core v1.3.1
8+
)
9+
10+
require (
11+
github.com/fsnotify/fsnotify v1.7.0 // indirect
12+
github.com/google/gopacket v1.1.19 // indirect
13+
github.com/gorilla/websocket v1.5.1 // indirect
14+
github.com/hashicorp/hcl v1.0.0 // indirect
15+
github.com/lionsoul2014/ip2region v2.11.2+incompatible // indirect
16+
github.com/magiconair/properties v1.8.7 // indirect
17+
github.com/mattn/go-colorable v0.1.13 // indirect
18+
github.com/mattn/go-isatty v0.0.20 // indirect
19+
github.com/mitchellh/mapstructure v1.5.0 // indirect
20+
github.com/oschwald/maxminddb-golang v1.12.0 // indirect
21+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
22+
github.com/rodaine/table v1.2.0 // indirect
23+
github.com/sagikazarmark/locafero v0.4.0 // indirect
24+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
25+
github.com/sourcegraph/conc v0.3.0 // indirect
26+
github.com/spf13/afero v1.11.0 // indirect
27+
github.com/spf13/cast v1.6.0 // indirect
28+
github.com/spf13/pflag v1.0.5 // indirect
29+
github.com/spf13/viper v1.18.2 // indirect
30+
github.com/subosito/gotenv v1.6.0 // indirect
31+
github.com/tidwall/gjson v1.17.1 // indirect
32+
github.com/tidwall/match v1.1.1 // indirect
33+
github.com/tidwall/pretty v1.2.1 // indirect
34+
github.com/tsosunchia/powclient v0.1.5 // indirect
35+
go.uber.org/multierr v1.11.0 // indirect
36+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
37+
golang.org/x/net v0.25.0 // indirect
38+
golang.org/x/sync v0.7.0 // indirect
39+
golang.org/x/sys v0.20.0 // indirect
40+
golang.org/x/text v0.15.0 // indirect
41+
gopkg.in/ini.v1 v1.67.0 // indirect
42+
gopkg.in/yaml.v3 v3.0.1 // indirect
43+
)

0 commit comments

Comments
 (0)