This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
-
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
1 parent
b286466
commit 656e6e5
Showing
5 changed files
with
172 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
*.exe |
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,2 +1,15 @@ | ||
# i-nuist-keeper | ||
保持你的i-NUIST校园网总是在线。 | ||
保持你的 i-NUIST 校园网总是在线。 | ||
## 特点 | ||
- 使用轻盈快速的[V](https://vlang.io/)实现 | ||
- 保存用户信息后自动登录 | ||
- 每6秒进行一次网络检测,在断线时快速重新登录 | ||
## 设置开机启动 - Windows | ||
1. `Win + R`后键入`shell:Common Startup` | ||
2. 在打开的文件夹中加入本程序的快捷方式即可 | ||
## 版本 | ||
```text | ||
V 0.3.2 26d643f | ||
``` | ||
## 搜索关键词优化 | ||
南京信息工程大学 NUIST 南信大 龙王山皇家气象学院 i-NUIST 校园网 脚本 |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Write-Output "Detected V: " | ||
Get-Command v | ||
Write-Output "Version: " | ||
v version | ||
v -o i-nuist-keeper.exe -os windows . | ||
Write-Output "Compilation done" | ||
Pause |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
cat "Detected V: " | ||
which v | ||
cat "Version: " | ||
v version | ||
v -o i-nuist-keeper.exe -os windows . | ||
cat "Compilation done" | ||
read -rsp $'Press any key to continue...\n' -n 1 key |
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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
//V 0.3.2 26d643f | ||
|
||
import net.http | ||
import os | ||
import time | ||
|
||
struct Info { | ||
mut: | ||
acc string | ||
pwd string | ||
ip string | ||
isp struct { | ||
mut: | ||
name string | ||
no string | ||
} | ||
} | ||
|
||
fn main() { | ||
println('本项目地址: https://github.com/carolyn-sun/i-nuist-keeper') | ||
if scan()! != true { | ||
mut info := Info { | ||
acc: os.input('请键入用户名: ') | ||
pwd: os.input('请键入密码: ') | ||
isp: struct { | ||
no: os.input('请键入运营商序号(移动/电信/联通对应2/3/4): ') | ||
} | ||
} | ||
info.isp.name = no2name(info.isp.no) | ||
if login(info)! { | ||
println('登录成功, 用户信息已经保存') | ||
} | ||
} | ||
println('程序将在此每6秒检测一次网络连接性, 你可以将其最小化但请勿关闭') | ||
println('前往本项目地址了解设置为开机自启的办法') | ||
for { | ||
if check()! != true { | ||
println('网络连接丢失, 正在尝试重新登录使你在线') | ||
start_check()! | ||
if check()! { | ||
println('重连成功') | ||
} | ||
} | ||
time.sleep(6000 * time.millisecond) | ||
} | ||
} | ||
|
||
fn get_ip() !string { | ||
res := http.get('http://10.255.255.34/api/v1/ip') or { | ||
println('Error1: 无法连接到i-NUIST: 检查你的无线网络设置') | ||
}.body | ||
if res.all_after('\"code\":').all_before(',\"data\"').contains_any('200') { | ||
return res.all_after('\"data\":\"').all_before('\"}') | ||
} | ||
return 'NULL' | ||
} | ||
|
||
fn login(info Info) !bool { | ||
ip := get_ip()! | ||
if ip != 'NULL' { | ||
payload := '{\"username\":\"$info.acc\",\"password\":\"$info.pwd\",\"channel\":\"$info.isp.no\",' | ||
+ '\"ifautologin\":\"1\",\"pagesign\":\"secondauth\",\"usripadd\":\"$ip\"}' | ||
res := http.post('http://10.255.255.34/api/v1/login/', payload) or { | ||
return false | ||
}.body | ||
if res.all_after('\"message\": ').all_before_last(',').contains_any('ok') && check()! { | ||
raw := '{\"username\":\"$info.acc\",\"password\":\"$info.pwd\",\"channel\":\"$info.isp.no\",' | ||
+ '\"ifautologin\":\"1\",\"pagesign\":\"secondauth\",\"usripadd\":\"' | ||
write(raw) or { | ||
println('Error3: 文件写入错误: 检查AppData目录的权限') | ||
return false | ||
} | ||
return true | ||
} else { | ||
println('Error2: 暂时无法认证, 可能是因为故障, 或欠费/帐号信息有误') | ||
} | ||
} | ||
return false | ||
} | ||
|
||
|
||
fn check() !bool { | ||
resp := http.get('http://dns.alidns.com/resolve?name=taobao.com.&type=1')! | ||
res := resp.body | ||
if res.contains_any('\"Status\":0') && res.contains_any('TTL') { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
fn write(raw string) !bool { | ||
url := os.config_dir()! + '\\i-nuist-keeper-cache.dat' | ||
os.write_file(url, raw) or { | ||
println('Error3: 文件写入错误: 检查AppData目录的权限') | ||
return false | ||
} | ||
println("帐号信息已经保存在本地, 位置为$url") | ||
return true | ||
} | ||
|
||
fn read() !string { | ||
url := os.config_dir()! + '\\i-nuist-keeper-cache.dat' | ||
if os.exists(url) { | ||
return os.read_file(url) or { | ||
'NULL' | ||
} | ||
} | ||
return 'NULL' | ||
} | ||
|
||
fn start_check() !bool { | ||
raw := read()! | ||
if raw != 'NULL' { | ||
ip := get_ip()! | ||
payload := raw + '\"$ip\"}' | ||
http.post('http://10.255.255.34/api/v1/login/', payload) or { | ||
println('Error2: 暂时无法认证, 可能是因为故障, 或欠费/帐号信息有误') | ||
return false | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
fn no2name(no string) string { | ||
return match no { | ||
'2' {'中国移动'} | ||
'3' {'中国电信'} | ||
'4' {'中国联通'} | ||
else {'未定义'} | ||
} | ||
} | ||
|
||
fn scan() !bool { | ||
url := os.config_dir()! + '\\i-nuist-keeper-cache.dat' | ||
if start_check()! { | ||
println('检测到保存在本地的帐号, 已经使用此帐号登录成功') | ||
println('如果要使用别的帐号登录, 请在关闭程序后删除$url') | ||
return true | ||
} | ||
return false | ||
} |