mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2024-11-16 10:51:13 +00:00
22 lines
330 B
Go
22 lines
330 B
Go
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
|
|
}
|