mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +02:00
18 lines
324 B
Go
18 lines
324 B
Go
package netutils
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
// PingTCP "pings" the IP address using TCP.
|
|
func PingTCP(ctx context.Context, ip net.IP, port int) error {
|
|
var dialer net.Dialer
|
|
conn, err := dialer.DialContext(ctx, "tcp", fmt.Sprintf("%s:%d", ip, port))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
conn.Close()
|
|
return nil
|
|
}
|