mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-01 22:09:26 +00:00
Server handling refactor (#27)
This commit is contained in:
@ -5,17 +5,20 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const scannerTimeOut = 3 * time.Second
|
||||
|
||||
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)
|
||||
conn, err := net.DialTimeout(p.Address.Network(), p.Address.String(), scannerTimeOut)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if conn != nil {
|
||||
defer conn.Close()
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user