fix:修复DNS缓存导致的网络检查不正确的问题
This commit is contained in:
@@ -17,6 +17,7 @@ type LoginInfo struct {
|
||||
UrlLoginPage string
|
||||
UrlGetChallengeApi string
|
||||
UrlLoginApi string
|
||||
UrlCheckApi string
|
||||
|
||||
Ip string
|
||||
Token string
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
7
main.go
7
main.go
@@ -6,13 +6,14 @@ import (
|
||||
"Mmx/Util"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Step0: 检查状态…")
|
||||
G := Util.Config.Init()
|
||||
|
||||
if Global.Config.Settings.QuitIfNetOk && Util.Checker.NetOk() {
|
||||
if Global.Config.Settings.QuitIfNetOk && Util.Checker.NetOk(G.UrlCheckApi) {
|
||||
fmt.Println("网络正常,程序退出")
|
||||
return
|
||||
}
|
||||
@@ -56,7 +57,7 @@ func main() {
|
||||
G.EncryptedChkstr = Util.Sha1(chkstr)
|
||||
|
||||
res, err := Request.Get(G.UrlLoginApi, map[string]string{
|
||||
"callback": "jQuery1124011576657442209481_1602812074032",
|
||||
"callback": "jQuery112401157665",
|
||||
"action": "login",
|
||||
"username": G.Form.UserName,
|
||||
"password": G.EncryptedMd5,
|
||||
@@ -69,7 +70,7 @@ func main() {
|
||||
"os": "Windows 10",
|
||||
"name": "windows",
|
||||
"double_stack": "0",
|
||||
"_": "1602812428675",
|
||||
"_": fmt.Sprint(time.Now().UnixNano()),
|
||||
})
|
||||
Util.ErrHandler(err)
|
||||
G.LoginResult, err = Util.GetResult(res)
|
||||
|
||||
Reference in New Issue
Block a user