Files
BitSrunLoginGo/util/checker.go
2021-07-11 12:02:42 +08:00

24 lines
462 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package util
import (
"context"
"net"
)
type checker struct{}
var Checker checker
func (checker) NetOk() bool {
r := &net.Resolver{ //指定DNS防止本地DNS缓存影响
PreferGo: true,
Dial: NetDailEr(),
}
if ip, err := r.LookupIP(context.Background(), "ip4", "www.msftconnecttest.com"); err != nil { //通过DNS确认是否在线
return false
} else if len(ip) == 0 || ip[0].String() != "13.107.4.52" {
return false
}
return true
}