Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ python login_once.py
```angular2html
python always_online.py
```

或者使用Windows 自带的计划任务计划程序 跑`python login_once.py` 防止后台被杀

![Alt text](win.png)

Linux系可以使用`crontab`

### 抄的!抄的!抄的!
- 楼主入学的时候深澜软件的网络认证页面已经经过混淆了,还好GitHub有大佬之前写好的登录流程相关代码。
所以就完全照着抄了这个https://github.com/coffeehat/BIT-srun-login-script
Expand Down
28 changes: 22 additions & 6 deletions always_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@
except:
pass

def is_connect_internet(test_ip):
if platform.system().lower().startswith('windows'):
cmd = u"ping {} -n 1".format(test_ip)

def is_connect_internet(test_ip, tun_mode=True):
# clash的TUN模式下,ping会被劫持,所以无法判断是否联网
# 因此推荐使用下面的检测联网方式
if not tun_mode:
if platform.system().lower().startswith('windows'):
cmd = u"ping {} -n 1".format(test_ip)
else:
cmd = u"ping {} -c 1".format(test_ip)
status = os.system(cmd)
return status == 0
else:
cmd = u"ping {} -c 1".format(test_ip)
status = os.system(cmd)
return status == 0
import re
myre = re.compile(
'^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$')
try:
_ip = os.popen("curl 4.ipw.cn").readline().strip()
print(_ip)
# print(myre.match(_ip).group())
# print(myre.match(_ip).group() == _ip)
return myre.match(_ip).group() == _ip
except Exception:
return False

def always_login(user=None, test_ip=None, delay=2, max_failed=3, **kwargs):
time_now = lambda: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
Expand Down
11 changes: 11 additions & 0 deletions auto-login.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 不在同一个文件夹下 不设置起始地址的时候需要在代码更换地址
# $job = Start-Job -ScriptBlock {cd C:\path-to-AutoLoginUESTC-main; python login_once.py}
$job = Start-Job -ScriptBlock {python login_once.py}

Wait-Job $job

# 不需要日志可以注释这两行
$TimeLog = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
"${TimeLog} `n $(Receive-Job $job)`n`n" >> auto-login-log.txt

Remove-Job $job
Binary file added win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.