Add endopoint to check is a given port is open on the client (#22)

This commit is contained in:
2023-12-31 12:52:08 +01:00
committed by GitHub
parent 2bbeeb34c5
commit f8e27bef56
8 changed files with 262 additions and 173 deletions

21
service/port_scanner.go Normal file
View File

@ -0,0 +1,21 @@
package service
import (
"net"
"time"
)
type PortScanner struct {
Address net.Addr
}
func (p *PortScanner) IsPortOpen() (bool, error) {
conn, err := net.DialTimeout(p.Address.Network(), p.Address.String(), 3*time.Second)
if err != nil {
return false, err
}
if conn != nil {
defer conn.Close()
}
return true, nil
}