|
|
|
@ -2,6 +2,7 @@ package dial
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -14,13 +15,15 @@ func PortDial(address, port, protocol string, timeout int) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("%v ping %v (%v) via port %v (timeout: %vs)...\n", protocol, address, ip, port, timeout)
|
|
|
|
fmt.Printf("%v ping %v (%v) via port %v (timeout: %vs)...\n", protocol, address, ip, port, timeout)
|
|
|
|
dialTarget := ip + ":" + port
|
|
|
|
dialTarget := ip + ":" + port
|
|
|
|
|
|
|
|
red := color.New(color.FgRed).SprintFunc()
|
|
|
|
|
|
|
|
green := color.New(color.FgGreen).SprintFunc()
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
startTime := time.Now()
|
|
|
|
startTime := time.Now()
|
|
|
|
conn, err := net.DialTimeout(protocol, dialTarget, time.Duration(timeout)*time.Second)
|
|
|
|
conn, err := net.DialTimeout(protocol, dialTarget, time.Duration(timeout)*time.Second)
|
|
|
|
endTime := time.Now()
|
|
|
|
endTime := time.Now()
|
|
|
|
elapsedTime := float64(endTime.Sub(startTime)) / float64(time.Millisecond)
|
|
|
|
elapsedTime := float64(endTime.Sub(startTime)) / float64(time.Millisecond)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("TIMEOUT via %v:%v time=%v ms\n", ip, port, elapsedTime)
|
|
|
|
fmt.Printf("%s via %v:%v time=%v ms\n", red("TIMEOUT"), ip, port, elapsedTime)
|
|
|
|
time.Sleep(time.Duration(timeout) * time.Second)
|
|
|
|
time.Sleep(time.Duration(timeout) * time.Second)
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -28,7 +31,7 @@ func PortDial(address, port, protocol string, timeout int) {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("OK via %v:%v time=%v ms\n", ip, port, elapsedTime)
|
|
|
|
fmt.Printf("%s via %v:%v time=%v ms\n", green("OK"), ip, port, elapsedTime)
|
|
|
|
time.Sleep(time.Duration(1) * time.Second)
|
|
|
|
time.Sleep(time.Duration(1) * time.Second)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|