use color red adjust

master
sre 4 years ago
parent f10532dd50
commit 88c7b93972

@ -9,6 +9,7 @@ import (
func PortDial(address, port, protocol string, timeout int) {
red := color.New(color.FgRed).SprintFunc()
yellow := color.New(color.FgYellow).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
ip := digIp(address)
if ip == "" {
@ -32,7 +33,12 @@ func PortDial(address, port, protocol string, timeout int) {
if err != nil {
return
}
fmt.Printf("%s via %v:%v time=%v ms\n", green("OK"), ip, port, elapsedTime)
if elapsedTime <= 500 {
fmt.Printf("%s via %v:%v time=%v ms\n", green("OK"), ip, port, elapsedTime)
} else {
fmt.Printf("%s via %v:%v time=%v ms\n", yellow("OK"), ip, port, elapsedTime)
}
time.Sleep(time.Duration(1) * time.Second)
continue
}

@ -157,11 +157,11 @@ func Ping(domain string, PS int) {
fmt.Println("Got signal:", s)
default:
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))
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 {
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))
fmt.Printf("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f %s\n", len, raddr.String(), raddr.String(), icmp_seq, dur, yellow("ms"))
} 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("%d bytes from %s (%s): icmp_seq=%d ttl=53 time=%.3f %s\n", len, raddr.String(), raddr.String(), icmp_seq, dur, red("ms"))
//fmt.Printf("来自 %s 的回复: 大小 = %d byte 时间 = %.3fms\n", raddr.String(), len, dur)
}

Loading…
Cancel
Save