feat: support dynv6

This commit is contained in:
chinhwajie
2024-10-25 16:12:07 +08:00
parent 938421fcc8
commit f18ca66786
7 changed files with 190 additions and 4 deletions

16
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/bitsrun/main.go",
"args": ["--config=./config.yaml"]
}
]
}

51
cmd/bitsrun/config.yaml Normal file
View File

@@ -0,0 +1,51 @@
form:
domain: net3.zju.edu.cn #登录地址 ip 或域名
username: "3210300237" #账号
user_type: #运营商类型,详情看下方文字说明
password: "P@ssw0rd" #密码
meta: #登录参数
"n": "200"
type: "1"
acid: "82"
enc: srun_bx1 # enc 不在表单中,但一般都是默认值。你可以使用 --auto-enc 或在 js 中搜索 enc 来找到真实值
os: Windows 10
name: windows
info_prefix: SRBX1 # info 字段前缀括号中的值
double_stack: false
settings:
basic: #基础设置
https: true #访问校园网 API 时使用 https 协议
skip_cert_verify: false #跳过证书有效校验
timeout: 5 #网络请求超时时间(秒,正整数)
interfaces: "" #网卡名称正则注意转义eth0\.[2-3],不为空时为多网卡模式
interfaces_interval: 0 # 秒,多网卡模式切换网卡时触发的等待时间
guardian: #守护模式(后台常驻)
enable: false
duration: 60 #网络检查周期(秒,正整数)
backoff: # 积分退避
enable: false # 开启后同时对所有运行模式生效,作用于登录失败的重试
max_retries: 0 # 为 0 时无限重试直至成功
initial_duration: 2 # 初始失败等待时间,秒
max_duration: 300 # 最大失败等待时间,秒
# 等待时间计算公式详见 https://github.com/Mmx233/BackoffCli
exponent_factor: 1 # 指数因子
inter_const_factor: 0 # 内常数因子,秒
outer_const_factor: 0 # 外常数因子,秒
log:
debug_level: true #打印调试日志
write_file: true #写日志文件
log_path: ./logs #日志文件存放目录路径
log_name: "srun_login.log" #指定日志文件名
ddns: #校园网内网 ip ddns
enable: true
domain: chizzyhub.dns.navy
ttl: 600
provider: "dynv6"
config: #这段配置是动态的,需要根据 provider 类型配置字段名,见 DDNS 说明
zone: "xxxx"
token: "ns4ReUsNKCSxpJD_zsVBMouGPwxUYS"
reality: #从指定地址模拟浏览器行为进入登录页,如果登录未出现问题不用启用
enable: false
addr: http://www.baidu.com #初始地址,需要使用 http、域名
custom_header: #这段配置是动态的,用于设置请求头,可以自由填写
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

View File

@@ -0,0 +1,44 @@
2024-10-25 15:26:10 [INFO] [comp:login] 正在获取登录状态
2024-10-25 15:26:10 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 15:26:11 [DEBU] [comp:login] jQuery432645995261979557719_1729841170991({"ServerFlag":4294967040,"add_time":1729673146,"all_bytes":22037913274,"bytes_in":21028237907,"bytes_out":1009675367,"checkout_date":0,"domain":"","error":"ok","keepalive_time":1729840060,"online_ip":"10.195.31.248","real_name":"","remain_seconds":0,"sum_bytes":3878849621331,"sum_seconds":54051552,"sysver":"1.01.20210926","user_balance":0,"user_charge":0,"user_mac":"DC-62-94-2B-16-37","user_name":"3210300237","wallet_balance":0})
2024-10-25 15:26:11 [DEBU] [comp:login] 认证客户端 ip: 10.195.31.248
2024-10-25 15:26:11 [INFO] [comp:login] 已登录~
2024-10-25 15:26:35 [INFO] [comp:login] 正在获取登录状态
2024-10-25 15:26:35 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 15:26:35 [DEBU] [comp:login] jQuery361456629475969236614_1729841195705({"ServerFlag":4294967040,"add_time":1729673146,"all_bytes":22037913274,"bytes_in":21028237907,"bytes_out":1009675367,"checkout_date":0,"domain":"","error":"ok","keepalive_time":1729840085,"online_ip":"10.195.31.248","real_name":"","remain_seconds":0,"sum_bytes":3878849621331,"sum_seconds":54051552,"sysver":"1.01.20210926","user_balance":0,"user_charge":0,"user_mac":"DC-62-94-2B-16-37","user_name":"3210300237","wallet_balance":0})
2024-10-25 15:26:35 [DEBU] [comp:login] 认证客户端 ip: 10.195.31.248
2024-10-25 15:26:35 [INFO] [comp:login] 已登录~
2024-10-25 15:30:14 [INFO] [comp:login] 正在获取登录状态
2024-10-25 15:30:18 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 15:30:18 [DEBU] [comp:login] jQuery432699188716976489386_1729841418263({"ServerFlag":4294967040,"add_time":1729673146,"all_bytes":22061994531,"bytes_in":21046657053,"bytes_out":1015337478,"checkout_date":0,"domain":"","error":"ok","keepalive_time":1729840307,"online_ip":"10.195.31.248","real_name":"","remain_seconds":0,"sum_bytes":3878849621331,"sum_seconds":54051552,"sysver":"1.01.20210926","user_balance":0,"user_charge":0,"user_mac":"DC-62-94-2B-16-37","user_name":"3210300237","wallet_balance":0})
2024-10-25 15:32:20 [INFO] [comp:login] 正在获取登录状态
2024-10-25 15:32:20 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 15:32:20 [DEBU] [comp:login] jQuery647425562398281391888_1729841540910({"client_ip":"10.195.31.248","ecode":0,"error":"not_online_error","error_msg":"","online_ip":"10.195.31.248","res":"not_online_error","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","st":1729840430})
2024-10-25 15:32:49 [DEBU] [comp:login] 认证客户端 ip: 10.195.31.248
2024-10-25 15:32:58 [INFO] [comp:login] 检测到用户未登录,开始尝试登录...
2024-10-25 15:32:59 [DEBU] [comp:login] 正在获取 Token
2024-10-25 15:32:59 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/get_challenge
2024-10-25 15:32:59 [DEBU] [comp:login] jQuery519578389322845648731_1729841579781({"challenge":"7834b4800930e0bbf49c6602d83012918f7236def9ad936aafe883dc7432d895","client_ip":"10.195.31.248","ecode":0,"error":"ok","error_msg":"","expire":"60","online_ip":"10.195.31.248","res":"ok","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","st":1729840469})
2024-10-25 15:32:59 [DEBU] [comp:login] token: 7834b4800930e0bbf49c6602d83012918f7236def9ad936aafe883dc7432d895
2024-10-25 15:32:59 [DEBU] [comp:login] 发送登录请求
2024-10-25 15:32:59 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/srun_portal
2024-10-25 15:33:00 [DEBU] [comp:login] jQuery569456671632598969985_1729841579803({"ServerFlag":0,"ServicesIntfServerIP":"127.0.0.1","ServicesIntfServerPort":"8001","access_token":"7834b4800930e0bbf49c6602d83012918f7236def9ad936aafe883dc7432d895","checkout_date":0,"client_ip":"10.195.31.248","ecode":0,"error":"ok","error_msg":"","online_ip":"10.195.31.248","ploy_msg":"E0000: Login is successful.","real_name":"","remain_flux":0,"remain_times":0,"res":"ok","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","suc_msg":"login_ok","sysver":"1.01.20210926","username":"3210300237","wallet_balance":0})
2024-10-25 15:33:07 [INFO] [comp:login] 登录成功~
2024-10-25 16:08:22 [INFO] [comp:login] 正在获取登录状态
2024-10-25 16:08:22 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 16:08:22 [DEBU] [comp:login] jQuery179763331345311585583_1729843702641({"ServerFlag":4294967040,"add_time":1729840469,"all_bytes":207335899,"bytes_in":193804335,"bytes_out":13531564,"checkout_date":0,"domain":"","error":"ok","keepalive_time":1729842591,"online_ip":"10.195.31.248","real_name":"","remain_seconds":0,"sum_bytes":3900915114721,"sum_seconds":54218824,"sysver":"1.01.20210926","user_balance":0,"user_charge":0,"user_mac":"DC-62-94-2B-16-37","user_name":"3210300237","wallet_balance":0})
2024-10-25 16:09:27 [INFO] [comp:login] 正在获取登录状态
2024-10-25 16:09:27 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/rad_user_info
2024-10-25 16:09:27 [DEBU] [comp:login] jQuery682821166611213443428_1729843767281({"client_ip":"10.195.31.248","ecode":0,"error":"not_online_error","error_msg":"","online_ip":"10.195.31.248","res":"not_online_error","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","st":1729842656})
2024-10-25 16:09:42 [DEBU] [comp:login] 认证客户端 ip: 10.195.31.248
2024-10-25 16:09:42 [INFO] [comp:login] 检测到用户未登录,开始尝试登录...
2024-10-25 16:09:42 [DEBU] [comp:login] 正在获取 Token
2024-10-25 16:09:42 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/get_challenge
2024-10-25 16:09:42 [DEBU] [comp:login] jQuery531657297747972145968_1729843782234({"challenge":"5c1d39b7fbb175f04bd891a61ee200dbbf231074daf84cab75243d84f037ebdd","client_ip":"10.195.31.248","ecode":0,"error":"ok","error_msg":"","expire":"60","online_ip":"10.195.31.248","res":"ok","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","st":1729842671})
2024-10-25 16:09:42 [DEBU] [comp:login] token: 5c1d39b7fbb175f04bd891a61ee200dbbf231074daf84cab75243d84f037ebdd
2024-10-25 16:09:42 [DEBU] [comp:login] 发送登录请求
2024-10-25 16:09:42 [DEBU] [comp:login] HTTP GET https://net3.zju.edu.cn/cgi-bin/srun_portal
2024-10-25 16:09:42 [DEBU] [comp:login] jQuery468675553329353563464_1729843782261({"ServerFlag":0,"ServicesIntfServerIP":"127.0.0.1","ServicesIntfServerPort":"8001","access_token":"5c1d39b7fbb175f04bd891a61ee200dbbf231074daf84cab75243d84f037ebdd","checkout_date":0,"client_ip":"10.195.31.248","ecode":0,"error":"ok","error_msg":"","online_ip":"10.195.31.248","ploy_msg":"E0000: Login is successful.","real_name":"","remain_flux":0,"remain_times":0,"res":"ok","srun_ver":"SRunCGIAuthIntfSvr V1.18 B20210926","suc_msg":"login_ok","sysver":"1.01.20210926","username":"3210300237","wallet_balance":0})
2024-10-25 16:09:42 [INFO] [comp:login] 登录成功~
2024-10-25 16:09:43 [INFO] [comp:login] [mod:ddns] 开始 dynv6 DDNS 流程
2024-10-25 16:10:29 [DEBU] [comp:login] [mod:ddns] addresses unchanged

51
config.yaml Normal file
View File

@@ -0,0 +1,51 @@
form:
domain: net3.zju.edu.cn #登录地址 ip 或域名
username: "3210300237" #账号
user_type: #运营商类型,详情看下方文字说明
password: "P@ssw0rd" #密码
meta: #登录参数
"n": "200"
type: "1"
acid: "82"
enc: srun_bx1 # enc 不在表单中,但一般都是默认值。你可以使用 --auto-enc 或在 js 中搜索 enc 来找到真实值
os: Windows 10
name: windows
info_prefix: SRBX1 # info 字段前缀括号中的值
double_stack: false
settings:
basic: #基础设置
https: true #访问校园网 API 时使用 https 协议
skip_cert_verify: false #跳过证书有效校验
timeout: 5 #网络请求超时时间(秒,正整数)
interfaces: "" #网卡名称正则注意转义eth0\.[2-3],不为空时为多网卡模式
interfaces_interval: 0 # 秒,多网卡模式切换网卡时触发的等待时间
guardian: #守护模式(后台常驻)
enable: false
duration: 60 #网络检查周期(秒,正整数)
backoff: # 积分退避
enable: false # 开启后同时对所有运行模式生效,作用于登录失败的重试
max_retries: 0 # 为 0 时无限重试直至成功
initial_duration: 2 # 初始失败等待时间,秒
max_duration: 300 # 最大失败等待时间,秒
# 等待时间计算公式详见 https://github.com/Mmx233/BackoffCli
exponent_factor: 1 # 指数因子
inter_const_factor: 0 # 内常数因子,秒
outer_const_factor: 0 # 外常数因子,秒
log:
debug_level: true #打印调试日志
write_file: true #写日志文件
log_path: ./logs #日志文件存放目录路径
log_name: "srun_login.log" #指定日志文件名
ddns: #校园网内网 ip ddns
enable: false
domain: www.example.com
ttl: 600
provider: "cloudflare"
config: #这段配置是动态的,需要根据 provider 类型配置字段名,见 DDNS 说明
zone: "xxxx"
token: "xxxx"
reality: #从指定地址模拟浏览器行为进入登录页,如果登录未出现问题不用启用
enable: false
addr: http://www.baidu.com #初始地址,需要使用 http、域名
custom_header: #这段配置是动态的,用于设置请求头,可以自由填写
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

View File

@@ -3,6 +3,9 @@ package dns
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"net/http"
"github.com/Mmx233/BitSrunLoginGo/internal/dns/aliyun" "github.com/Mmx233/BitSrunLoginGo/internal/dns/aliyun"
"github.com/Mmx233/BitSrunLoginGo/internal/dns/cloudflare" "github.com/Mmx233/BitSrunLoginGo/internal/dns/cloudflare"
"github.com/Mmx233/BitSrunLoginGo/internal/dns/dnspod" "github.com/Mmx233/BitSrunLoginGo/internal/dns/dnspod"
@@ -28,6 +31,25 @@ func Run(c *Config) error {
dns, err = cloudflare.New(int(c.TTL), c.Conf.Cloudflare, c.Http) dns, err = cloudflare.New(int(c.TTL), c.Conf.Cloudflare, c.Http)
case "dnspod": case "dnspod":
dns, err = dnspod.New(uint64(c.TTL), c.Conf.DnsPod, c.Http.Transport) dns, err = dnspod.New(uint64(c.TTL), c.Conf.DnsPod, c.Http.Transport)
case "dynv6":
url := fmt.Sprintf(
"http://dynv6.com/api/update?hostname=%s&token=%s&ipv4=%s", c.Domain, c.Conf.Token, c.IP)
// Make the HTTP GET request
resp, err := http.Get(url)
if err != nil {
c.Logger.Error(err)
return err
}
// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
c.Logger.Error(err)
return err
}
// Print the response
c.Logger.Debug(string(body))
resp.Body.Close()
default: default:
var msg string var msg string
if c.Provider == "" { if c.Provider == "" {

View File

@@ -3,6 +3,10 @@ package login
import ( import (
"context" "context"
"errors" "errors"
"net/http"
"sync"
"time"
"github.com/Mmx233/BackoffCli/backoff" "github.com/Mmx233/BackoffCli/backoff"
"github.com/Mmx233/BitSrunLoginGo/internal/config" "github.com/Mmx233/BitSrunLoginGo/internal/config"
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags" "github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
@@ -12,9 +16,6 @@ import (
"github.com/Mmx233/BitSrunLoginGo/pkg/srun" "github.com/Mmx233/BitSrunLoginGo/pkg/srun"
"github.com/Mmx233/BitSrunLoginGo/tools" "github.com/Mmx233/BitSrunLoginGo/tools"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http"
"sync"
"time"
) )
var ipLast string var ipLast string

View File

@@ -4,8 +4,9 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"net/http" "net/http"
log "github.com/sirupsen/logrus"
) )
type Conf struct { type Conf struct {