use color red

master
sre 4 years ago
parent 09803ed982
commit f10532dd50

@ -114,6 +114,9 @@ func Ping(domain string, PS int) {
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill) 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 { for {
/* /*
@ -153,8 +156,15 @@ func Ping(domain string, PS int) {
os.Exit(0) os.Exit(0)
fmt.Println("Got signal:", s) fmt.Println("Got signal:", s)
default: 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) 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) //fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur)
}
icmp_seq++ icmp_seq++
time.Sleep(time.Second) time.Sleep(time.Second)
} }

@ -5,13 +5,13 @@ pong www.baidu.com 443 -t 1
pong www.baidu.com 443 -t 1 -k udp pong www.baidu.com 443 -t 1 -k udp
pong -a www.baidu.com -p 443 -k tcp -t 3 pong -a www.baidu.com -p 443 -k tcp -t 3
## build ## build
```bash ```bash
cd /root cd /root
rm -rf pong rm -rf pong
git clone https://git.sre.ink/go/pong.git git clone https://git.sre.ink/go/pong.git
cd pong 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 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 rm -rf /usr/bin/pong
mv pong /usr/bin/ mv pong /usr/bin/

Loading…
Cancel
Save