由于学校(广西某校)做了多设备检测,因有其他东西在运行不能断网,因此特意写出这么一个脚本方便自己用,本来个人使用为了应某人需求,特地发出来。
默认使用学生账号登录,应该没老师账号吧?
注意需要安装python模块:requests,如果没有安装shell环境下安装:
python -m pip install requests
需要修改账号、密码,多少秒检查一次看个人情况来,其他看注释。脚本如下:
# coding:utf-8
import time, datetime
import requests
def print_time():
times = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return times
def get_requests(username, pwd, operator, timeout, ua):
try:
url = 'https://www.jiubanyipeng.com/' # 不能使用百度的,有缓存无法正常获取到值
ss = requests.get(url=url, timeout=3)
print('正常联网:', ss, print_time())
time.sleep(int(timeout))
except Exception as s:
print('连网外网失败:', s)
print('正在尝试重新联网', print_time())
Host = f'http://10.251.251.250/drcom/login?callback=dr1003&DDDDD={username}&upass={pwd}&0MKKey=123456&R1=0&R3={operator}&R6=0¶=00&v6ip=&v=8383 HTTP/1.1'
if ua == '1':
ua = 'Mozilla/5.0 (Linux; Android 9.0; SAMSUNG SM-F900U Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36'
else:
ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
header = {
'User-Agent': ua,
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'close',
'Referer': 'http://10.251.251.250/',
'Cookie': 'PHPSESSID=tieo1okr4h0cbjaeqmc7k7bhuj',
}
try:
run = requests.get(url=Host, headers=header,timeout=3)
print('重新联网成功')
print(run.text)
time.sleep(1)
except Exception as s:
print('连网失败:', s, print_time())
print('1秒后重新尝试重新联网', print_time())
time.sleep(1)
username = '19300000' # 账号
pwd = '000000' # 密码
operator = '1' # 移动为1,电信为3
timeout = '1' # 多少秒 检查一次是否正常联网
ua = '1' # 以什么设备登录,默认用手机设备登录,2是电脑端
while True:
get_requests(username,pwd,operator,timeout,ua)