Files
BitSrunLoginGo/Util/checker.go

37 lines
681 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 (
"Mmx/Request"
"fmt"
"net"
"time"
)
type checker struct{}
var Checker checker
func (checker) NetOk(url string) bool {
if ip, err := net.LookupIP("www.msftconnecttest.com"); err != nil { //通过DNS确认是否在线
return false
} else if len(ip) == 0 || ip[0].String() != "13.107.4.52" {
return false
}
{ //有些路由器有DNS缓存故进行进一步确认
body, err := Request.Get(url, map[string]string{
"callback": "jQuery1635413",
"_": fmt.Sprint(time.Now().UnixNano()),
})
ErrHandler(err)
r, err := GetResult(body)
if err != nil {
ErrHandler(err)
}
if r != "ok" {
return false
}
}
return true
}