diff --git a/dial/dial.go b/dial/dial.go index 9ebb5c5..8b1c61c 100644 --- a/dial/dial.go +++ b/dial/dial.go @@ -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 } diff --git a/goping/goping.go b/goping/goping.go index e825520..abc2aa1 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -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) }