mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2024-12-22 10:58:01 +00:00
25 lines
372 B
Go
25 lines
372 B
Go
package service
|
|
|
|
import (
|
|
"net"
|
|
"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(), scannerTimeOut)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if conn != nil {
|
|
defer conn.Close()
|
|
}
|
|
|
|
return true, nil
|
|
}
|