-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
886 additions
and
885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
## 一、STU-NET 程序说明 | ||
|
||
```sh | ||
(base) PS C:\Users\zlz_g> stu-net | ||
stu-net 是一款可以在命令行中运行的校园网工具。 | ||
可以用于无头环境下校园网的登录、登出、状态查询、流量查询。 | ||
|
||
Usage: | ||
stu-net [flags] | ||
stu-net [command] | ||
|
||
Available Commands: | ||
check 查看当前是否登录 | ||
completion Generate the autocompletion script for the specified shell | ||
flux 查询剩余流量 | ||
help Help about any command | ||
login 通过账号和密码登录到校园网 | ||
logout 登出校园网 | ||
restore 重置配罝文件 | ||
|
||
Flags: | ||
-h, --help help for stu-net | ||
-i, --interactive 使用交互模式 | ||
|
||
Use "stu-net [command] --help" for more information about a command. | ||
|
||
Examples: | ||
stu-net -i # 进入交互模式 | ||
stu-net login \ | ||
-u 20xxxxx \ | ||
-p my_pwd \ | ||
-s # 指定用户名和密码登录,同时将之保存到配置 | ||
stu-net flux # 查询流量 | ||
|
||
``` | ||
|
||
## 二、校园网接口说明 | ||
|
||
整个校园网的登录、登出、流量查询、状态查询都基于 `POST` 请求。 | ||
|
||
- 登录、登出、状态查询的 URL 都是: `https://a.stu.edu.cn:444/ac_portal/login.php` | ||
- 流量查询的 URL 是: `https://a.stu.edu.cn:444/ac_portal/userflux` | ||
|
||
它们 POST 的 payload 不同,下面详述。 | ||
|
||
### 1. 登录 | ||
|
||
登录成功后,除了会返回一个 表示成功的JSON;在响应头中,还会设置 cookie,这个 cookie 在流量查询时需要用到. | ||
|
||
响应头节选: `Set-Cookie:[AUTHSESSID=cd726d747d9e; HttpOnly;Secure;]` | ||
|
||
```py | ||
payload = { | ||
"opr": "pwdLogin", | ||
"userName": Username, # 20abcdef | ||
"pwd": Password, # mypassword | ||
"ipv4or6": "", | ||
"rememberPwd": "0" | ||
} | ||
``` | ||
|
||
### 2. 登出 | ||
|
||
```py | ||
payload = { | ||
"opr": "logout", | ||
"ipv4or6": "" | ||
} | ||
``` | ||
|
||
### 3. 流量查询 | ||
|
||
进行流量查询时,需要用到登录时获得的 cookie, 将 cookie 添加到请求头中,然后直接 POST 流量查询的 URL 即可,不需要参数。 | ||
|
||
|
||
### 4. 状态查询 | ||
|
||
```py | ||
payload = { | ||
"opr": "online_check" | ||
} | ||
``` | ||
## 一、STU-NET 程序说明 | ||
|
||
```sh | ||
(base) PS C:\Users\zlz_g> stu-net | ||
stu-net 是一款可以在命令行中运行的校园网工具。 | ||
可以用于无头环境下校园网的登录、登出、状态查询、流量查询。 | ||
|
||
Usage: | ||
stu-net [flags] | ||
stu-net [command] | ||
|
||
Available Commands: | ||
check 查看当前是否登录 | ||
completion Generate the autocompletion script for the specified shell | ||
flux 查询剩余流量 | ||
help Help about any command | ||
login 通过账号和密码登录到校园网 | ||
logout 登出校园网 | ||
restore 重置配罝文件 | ||
|
||
Flags: | ||
-h, --help help for stu-net | ||
-i, --interactive 使用交互模式 | ||
|
||
Use "stu-net [command] --help" for more information about a command. | ||
|
||
Examples: | ||
stu-net -i # 进入交互模式 | ||
stu-net login \ | ||
-u 20xxxxx \ | ||
-p my_pwd \ | ||
-s # 指定用户名和密码登录,同时将之保存到配置 | ||
stu-net flux # 查询流量 | ||
|
||
``` | ||
|
||
## 二、校园网接口说明 | ||
|
||
整个校园网的登录、登出、流量查询、状态查询都基于 `POST` 请求。 | ||
|
||
- 登录、登出、状态查询的 URL 都是: `https://a.stu.edu.cn:444/ac_portal/login.php` | ||
- 流量查询的 URL 是: `https://a.stu.edu.cn:444/ac_portal/userflux` | ||
|
||
它们 POST 的 payload 不同,下面详述。 | ||
|
||
### 1. 登录 | ||
|
||
登录成功后,除了会返回一个 表示成功的JSON;在响应头中,还会设置 cookie,这个 cookie 在流量查询时需要用到. | ||
|
||
响应头节选: `Set-Cookie:[AUTHSESSID=cd726d747d9e; HttpOnly;Secure;]` | ||
|
||
```py | ||
payload = { | ||
"opr": "pwdLogin", | ||
"userName": Username, # 20abcdef | ||
"pwd": Password, # mypassword | ||
"ipv4or6": "", | ||
"rememberPwd": "0" | ||
} | ||
``` | ||
|
||
### 2. 登出 | ||
|
||
```py | ||
payload = { | ||
"opr": "logout", | ||
"ipv4or6": "" | ||
} | ||
``` | ||
|
||
### 3. 流量查询 | ||
|
||
进行流量查询时,需要用到登录时获得的 cookie, 将 cookie 添加到请求头中,然后直接 POST 流量查询的 URL 即可,不需要参数。 | ||
|
||
|
||
### 4. 状态查询 | ||
|
||
```py | ||
payload = { | ||
"opr": "online_check" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
$AppName = "stu-net" | ||
$AppVer = "v0.3.1" | ||
|
||
Remove-Item dist\ -Force -Recurse | ||
|
||
Write-Output "Start Building..." | ||
|
||
Write-Output "Building for Linux amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "linux"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_linux_amd64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_linux_amd64.tar.gz dist/$($AppName)_$($AppVer)_linux_amd64 | ||
Write-Output "Building for darwin amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "darwin"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_darwin_amd64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_darwin_amd64.tar.gz dist/$($AppName)_$($AppVer)_darwin_amd64 | ||
Write-Output "Building for windows amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "windows"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_windows_amd64/$($AppName).exe | ||
Write-Output ".\stu-net.exe -i" >> "dist/$($AppName)_$($AppVer)_windows_amd64/start.bat" | ||
$compress = @{ | ||
Path = "dist/$($AppName)_$($AppVer)_windows_amd64" | ||
CompressionLevel = "Fastest" | ||
DestinationPath = "dist/$($AppName)_$($AppVer)_windows_amd64.zip" | ||
Force = $true | ||
} | ||
Compress-Archive @compress | ||
Write-Output "Building for Linux arm (such as Raspberry Pi) ... " | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "linux"; $ENV:GOARCH = "arm"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_linux_arm64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_linux_arm64.tar.gz dist/$($AppName)_$($AppVer)_linux_arm64 | ||
|
||
Write-Output "Build and Compress Complete. Cleaning up..." | ||
# force remove | ||
Remove-Item "dist/$($AppName)_$($AppVer)_linux_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_linux_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_darwin_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_darwin_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_windows_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_windows_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_linux_arm64" -Force -Recurse | ||
$AppName = "stu-net" | ||
$AppVer = "v0.3.1" | ||
|
||
Remove-Item dist\ -Force -Recurse | ||
|
||
Write-Output "Start Building..." | ||
|
||
Write-Output "Building for Linux amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "linux"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_linux_amd64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_linux_amd64.tar.gz dist/$($AppName)_$($AppVer)_linux_amd64 | ||
Write-Output "Building for darwin amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "darwin"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_darwin_amd64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_darwin_amd64.tar.gz dist/$($AppName)_$($AppVer)_darwin_amd64 | ||
Write-Output "Building for windows amd64..." | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "windows"; $ENV:GOARCH = "amd64"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_windows_amd64/$($AppName).exe | ||
Write-Output ".\stu-net.exe -i" >> "dist/$($AppName)_$($AppVer)_windows_amd64/start.bat" | ||
$compress = @{ | ||
Path = "dist/$($AppName)_$($AppVer)_windows_amd64" | ||
CompressionLevel = "Fastest" | ||
DestinationPath = "dist/$($AppName)_$($AppVer)_windows_amd64.zip" | ||
Force = $true | ||
} | ||
Compress-Archive @compress | ||
Write-Output "Building for Linux arm (such as Raspberry Pi) ... " | ||
$ENV:CGO_ENABLED = 0; $ENV:GOOS = "linux"; $ENV:GOARCH = "arm"; go build --ldflags "-s -w" -o dist/$($AppName)_$($AppVer)_linux_arm64/$($AppName) | ||
tar -zcvf dist/$($AppName)_$($AppVer)_linux_arm64.tar.gz dist/$($AppName)_$($AppVer)_linux_arm64 | ||
|
||
Write-Output "Build and Compress Complete. Cleaning up..." | ||
# force remove | ||
Remove-Item "dist/$($AppName)_$($AppVer)_linux_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_linux_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_darwin_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_darwin_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_windows_amd64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_windows_amd64" | ||
Remove-Item "dist/$($AppName)_$($AppVer)_linux_arm64" -Force -Recurse | ||
Write-Output "rm dist/$($AppName)_$($AppVer)_linux_arm64" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
package tools | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
const configTemp = `[Account] | ||
uname = | ||
pwd = | ||
key= | ||
verify= | ||
[Cache] | ||
time= | ||
cookie= | ||
` | ||
|
||
func CreateConfigFileIfNotExists(filePath string) { | ||
|
||
if !isFileExists(filePath) { | ||
file, err := createFile(filePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func(file *os.File) { | ||
err := file.Close() | ||
if err != nil { | ||
panic(err) | ||
} | ||
}(file) | ||
|
||
_, err = file.WriteString(configTemp) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = file.Sync() // 确保数据被刷新到磁盘 | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
} | ||
|
||
func isFileExists(filePath string) bool { | ||
_, err := os.Stat(filePath) | ||
if err == nil { | ||
return true | ||
} | ||
if os.IsNotExist(err) { | ||
return false | ||
} | ||
return false | ||
} | ||
|
||
func createFile(filePath string) (*os.File, error) { | ||
|
||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return file, nil | ||
} | ||
package tools | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
const configTemp = `[Account] | ||
uname = | ||
pwd = | ||
key= | ||
verify= | ||
[Cache] | ||
time= | ||
cookie= | ||
` | ||
|
||
func CreateConfigFileIfNotExists(filePath string) { | ||
|
||
if !isFileExists(filePath) { | ||
file, err := createFile(filePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func(file *os.File) { | ||
err := file.Close() | ||
if err != nil { | ||
panic(err) | ||
} | ||
}(file) | ||
|
||
_, err = file.WriteString(configTemp) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = file.Sync() // 确保数据被刷新到磁盘 | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
} | ||
|
||
func isFileExists(filePath string) bool { | ||
_, err := os.Stat(filePath) | ||
if err == nil { | ||
return true | ||
} | ||
if os.IsNotExist(err) { | ||
return false | ||
} | ||
return false | ||
} | ||
|
||
func createFile(filePath string) (*os.File, error) { | ||
|
||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return file, nil | ||
} |
Oops, something went wrong.