mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-01 23:19:26 +00:00
Add endopoint to check is a given port is open on the client (#22)
This commit is contained in:
21
service/port_scanner.go
Normal file
21
service/port_scanner.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user