whatismyip/service/port_scanner.go

25 lines
372 B
Go
Raw Normal View History

package service
import (
"net"
"time"
)
2024-03-23 16:41:34 +00:00
const scannerTimeOut = 3 * time.Second
type PortScanner struct {
Address net.Addr
}
func (p *PortScanner) IsPortOpen() (bool, error) {
2024-03-23 16:41:34 +00:00
conn, err := net.DialTimeout(p.Address.Network(), p.Address.String(), scannerTimeOut)
if err != nil {
return false, err
}
if conn != nil {
defer conn.Close()
}
2024-03-23 16:41:34 +00:00
return true, nil
}