Files
BitSrunLoginGo/util/checker.go
2021-12-03 19:59:42 +08:00

27 lines
471 B
Go

package util
import (
"github.com/Mmx233/tool"
"net"
"time"
)
type checker struct{}
var Checker checker
// NetOk 网络状况检查
func (checker) NetOk(timeout uint, localAddr net.Addr) bool {
h, i, e := tool.HTTP.GetReader(&tool.GetRequest{
Url: "https://www.baidu.com/",
Redirect: false,
Timeout: time.Duration(timeout) * time.Second,
LocalAddr: localAddr,
})
if e != nil {
return false
}
_ = i.Close()
return h.Get("Location") == ""
}