2023-09-30 16:56:37 +00:00
|
|
|
package scanner
|
2023-09-30 15:19:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2023-10-03 10:56:35 +00:00
|
|
|
func CheckTCPOpen(ctx Context, host string) (bool, string) {
|
2023-09-30 15:19:02 +00:00
|
|
|
// Just check if the connection is successful
|
2023-10-03 10:56:35 +00:00
|
|
|
d := net.Dialer{}
|
|
|
|
conn, err := d.DialContext(ctx, "tcp", host)
|
2023-09-30 16:15:11 +00:00
|
|
|
|
2023-10-03 10:56:35 +00:00
|
|
|
if err != nil {
|
2023-09-30 15:19:02 +00:00
|
|
|
// 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
|
|
|
}
|