diff --git a/goping/goping.go b/goping/goping.go index 5d9d390..e825520 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -114,6 +114,9 @@ func Ping(domain string, PS int) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill) + red := color.New(color.FgRed).SprintFunc() + green := color.New(color.FgGreen).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() for { /* 向目标地址发送二进制报文包 @@ -153,8 +156,15 @@ func Ping(domain string, PS int) { os.Exit(0) fmt.Println("Got signal:", s) default: - fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, dur) - //fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur) + if dur <= 30 { + fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, green(dur)) + } else if dur <= 500 { + fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, yellow(dur)) + } else { + fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f ms\n", len, raddr.String(), raddr.String(), icmp_seq, red(dur)) + //fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur) + } + icmp_seq++ time.Sleep(time.Second) } diff --git a/readme.md b/readme.md index 70deb01..ff47893 100644 --- a/readme.md +++ b/readme.md @@ -5,15 +5,15 @@ pong www.baidu.com 443 -t 1 pong www.baidu.com 443 -t 1 -k udp pong -a www.baidu.com -p 443 -k tcp -t 3 - ## build ```bash cd /root rm -rf pong git clone https://git.sre.ink/go/pong.git cd pong +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 rm -rf /usr/bin/pong mv pong /usr/bin/ pong www.baidu.com 443 -``` \ No newline at end of file +```