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)
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)
}

@ -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
```
```

Loading…
Cancel
Save