用于校园网定时检测是否需要认证
适用Dr.COM WEB 哆点校园网 认证
路由器 小米AC2100 (Xiaomi Mi Router AC2100)
系统环境
型号:Xiaomi Mi Router AC2100
架构:MediaTek MT7621 ver:1 eco:3
目标平台:ramips/mt7621
固件版本:ImmortalWrt 21.02-SNAPSHOT r19924-cc9a7cea38 / LuCI openwrt-21.02 branch git-22.358.06767-5f33747
内核版本:5.4.231
包含UA2F IPID 插件
自用仓库地址: https://github.com/bejix/OpenWrt-MiRoute-AC2100
使用方法
广西财经学院@
flag provided but not defined: -a
-run
持续运行
-type string
类型 : 1=联通 2=移动 (default "000000")
-upass string
密码 (default "CJXY@2021")
-user string
账号 (default "000000")
示例:./dr.com --type 1 --user 000000 --upass 0000001 --run
cron 程序保活脚本
#!/bin/sh
processNum=$(ps -w|grep dr.com|grep -v grep|grep -v dr.com.sh| wc -l)
if [ $processNum -eq 0 ];then
(/root/dr.com --type 1 --user 221005202150 --upass 0000001 --run >/dev/null 2>&1 )&
else
echo running
fi
CRON 定时
*/1 * * * * /root/dr.com.sh # 保后台校园网认证
代码
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"regexp"
"strconv"
"strings"
"time"
)
func checkLogin() bool {
client := http.Client{Timeout: 5 * time.Second}
response, err := client.Get("http://10.9.9.9/")
if err != nil {
log.Println(err)
return false
}
defer func() {
response.Body.Close()
}()
// <!--Dr.COMWebLoginID_1.htm--> 已经登陆
// <!--Dr.COMWebLoginID_0.htm--> 未登陆
body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
return false
}
return strings.Contains(string(body), "COMWebLoginID_1")
}
var (
Type string
User string
UPass string
run bool
)
func init() {
flag.StringVar(&Type, "type", "000000", "类型 : 1=联通 2=移动")
flag.StringVar(&User, "user", "000000", "账号")
flag.StringVar(&UPass, "upass", "CJXY@2021", "密码")
flag.BoolVar(&run, "run", false, "持续运行")
flag.Usage = func() {
flag.PrintDefaults()
}
}
func login() {
v := time.Now().Unix()
log.Println("Start Login")
urlQuery := "callback=dr1003&DDDDD=" + User + "&upass=" + UPass + "&0MKKey=123456&R1=0&R2=&R3=" + Type + "&R6=0¶=00&v6ip=&terminal_type=1&lang=zh-cn&jsVersion=4.1.3&v=" + strconv.Itoa(int(v)) + "&lang=zh"
response, err := http.Get(fmt.Sprintf("http://10.9.9.9/drcom/login?%s", urlQuery))
if err != nil {
log.Println(err)
return
}
defer func() {
if response != nil {
response.Body.Close()
}
}()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Println(err)
}
re := regexp.MustCompile(`"msga":".*?"`)
log.Println(re.FindString(string(body)))
}
func main() {
fmt.Println("广西财经学院@")
flag.Parse()
if checkLogin() {
log.Println("Successify")
} else {
login()
}
if run {
for {
if !checkLogin() {
log.Println("验证=》")
login()
}
time.Sleep(time.Second * 5)
}
}
}
编译
set GOOS=linux
set GOARCH=mipsle
set GOMIPS=softfloat
go build -ldflags="-s -w"
# 使用UPX压缩减少体积
upx -k -9 dr.com