package tcp

import (
	"fmt"
	"net"
	"time"
)

// CheckPortConnection 检测端口是否监听
func CheckPortConnection(ip string, port int) bool {
	conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 3*time.Second)
	if err != nil {
		return false
	} else {
		if conn != nil {
			defer func(conn net.Conn) {
				_ = conn.Close()
			}(conn)
			return true
		} else {
			return false
		}
	}
}
