2023-09-30 16:56:37 +00:00
|
|
|
package scanner
|
2023-09-30 15:19:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-09-30 16:19:41 +00:00
|
|
|
func CheckTCPOpen(host string) (bool, string) {
|
2023-09-30 15:19:02 +00:00
|
|
|
// Just check if the connection is successful
|
|
|
|
timeout := time.Second
|
2023-09-30 16:15:11 +00:00
|
|
|
conn, err := net.DialTimeout("tcp", host, timeout)
|
|
|
|
|
2023-09-30 15:19:02 +00:00
|
|
|
if err != nil || conn == nil {
|
|
|
|
// If timeout or anything else
|
2023-09-30 16:19:41 +00:00
|
|
|
return false, err.Error()
|
2023-09-30 15:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
2023-09-30 16:19:41 +00:00
|
|
|
return true, "OK"
|
2023-09-30 15:19:02 +00:00
|
|
|
}
|