diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d65ccd1 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: build-linux-arm64 build-linux-amd64 + +build-linux-arm64: + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -v -a -o pong pong.go + +build-linux-amd64: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on GOPROXY="https://goproxy.cn,direct" go mod tidy + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on GOPROXY="https://goproxy.cn,direct" go build -v -a -o pong pong.go \ No newline at end of file diff --git a/goping/goping.go b/goping/goping.go index f06b2b3..d81b969 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -126,6 +126,8 @@ func Ping(domain string, PS int) { fmt.Printf("%s\n", red("timeout")) dropPack++ time.Sleep(time.Second) + fmt.Println("666666666666666666666666666") + continue } // 否则记录当前得时间 @@ -140,23 +142,29 @@ func Ping(domain string, PS int) { dropPack++ time.Sleep(time.Second) continue + fmt.Println("777777777777777777777777777777777777777777") } t_end := time.Now() dur := float64(t_end.Sub(t_start).Nanoseconds()) / 1e6 ret_list = append(ret_list, dur) if dur < max_lan { max_lan = dur + fmt.Println("88888888888888888888888") } if dur > min_lan { min_lan = dur + fmt.Println("999999999999999999999999999999999") } - + fmt.Println("33333333333333333333333333333333333333333333333") select { case s := <-c: + fmt.Println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") foot(raddr.String(), icmp_seq, dropPack, min_lan, avg_lan, max_lan, ret_list) os.Exit(0) fmt.Println("Got signal:", s) + default: + fmt.Println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") if dur <= 50 { fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f %s\n", len, raddr.String(), raddr.String(), icmp_seq, dur, green("ms")) } else if dur <= 500 { diff --git a/goping/ping_test.go b/goping/ping_test.go index 2dcd47c..3288809 100644 --- a/goping/ping_test.go +++ b/goping/ping_test.go @@ -9,6 +9,9 @@ import ( "time" ) +func TestPing2(t *testing.T) { + Ping("www.baidu1.com", 48) +} func TestColor(tt *testing.T) { // Create SprintXxx functions to mix strings with other non-colorized strings: yellow := color.New(color.FgYellow).SprintFunc() diff --git a/readme.md b/readme.md index 9f5861c..ca0f368 100644 --- a/readme.md +++ b/readme.md @@ -16,8 +16,7 @@ cd /root rm -rf pong git clone https://git.sre.ink/go/pong.git cd pong -CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy -CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -v -a -o pong pong.go +make build-linux-arm64 rm -rf /usr/bin/pong mv pong /usr/bin/ pong www.baidu.com 443