mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2024-11-16 05:01:14 +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
|
|
}
|