status/scanner/tcp.go
2024-09-25 20:30:37 +00:00

21 lines
353 B
Go

package scanner
import (
"context"
"net"
)
func CheckTCPOpen(ctx context.Context, host string) (bool, string) {
// Just check if the connection is successful
d := net.Dialer{}
conn, err := d.DialContext(ctx, "tcp", host)
if err != nil {
// If timeout or anything else
return false, err.Error()
}
defer conn.Close()
return true, "OK"
}