fix:修复DNS缓存导致的网络检查不正确的问题

This commit is contained in:
Mmx
2021-03-17 22:28:02 +08:00
parent 2a2fc9643f
commit dd9f0b3a96
5 changed files with 28 additions and 7 deletions

View File

@@ -1,18 +1,36 @@
package Util
import (
"Mmx/Request"
"fmt"
"net"
"time"
)
type checker struct{}
var Checker checker
func (checker) NetOk() bool {
if ip, err := net.LookupIP("www.msftconnecttest.com"); err != nil {
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
}

View File

@@ -20,6 +20,7 @@ func (*config) Generate(Form *Modles.LoginForm, Meta *Modles.LoginMeta) *Modles.
UrlLoginPage: "http://" + Form.Domain + "/srun_portal_success",
UrlGetChallengeApi: "http://" + Form.Domain + "/cgi-bin/get_challenge",
UrlLoginApi: "http://" + Form.Domain + "/cgi-bin/srun_portal",
UrlCheckApi: "http://" + Form.Domain + "/cgi-bin/rad_user_info",
Meta: Meta,
Form: &Modles.LoginForm{
UserName: Form.UserName + "@cmcc",

View File

@@ -37,8 +37,8 @@ func GetResult(body string) (string, error) {
func Md5(content string) string {
w := md5.New()
_, _ = io.WriteString(w, content) //将str写入到w中
return fmt.Sprintf("%x", w.Sum(nil)) //w.Sum(nil)将w的hash转成[]byte格式
_, _ = io.WriteString(w, content)
return fmt.Sprintf("%x", w.Sum(nil))
}
func Sha1(content string) string {