2025-11-2715 min53 views
AUST自助上网-Python
#Threading#Web Requests#Networking#Python
AI Summary
每分钟最多 5 次
- 自动认证脚本: 该脚本使用Python编写,用于自动登录校园网络。它通过向指定的认证URL发送包含学号、密码和运营商信息的数据包来实现这一功能。
- 持续检测与重连: 脚本中包含一个循环,每隔1秒(或2秒)检查一次互联网连接状态。如果检测到未连接到互联网,则会尝试重新发送认证请求以恢复连接。
- 多线程处理用户输入: 为了允许用户在任何时候中断脚本运行,作者使用了多线程技术创建了一个监听用户输入的独立线程。当用户输入“q”时,程序将停止执行。
- 自定义请求头: 在检查互联网连接的过程中,脚本向百度网站发起请求,并设置了特定的User-Agent和Content-Length请求头,以模拟浏览器行为。
- 数据包构造: 认证所需的数据包包括用户名(学号加上运营商标识)、密码等字段,这些信息直接由用户输入提供。对于不同的网络服务提供商(如电信、联通、移动),需要在用户名后附加相应的标识符。
from requests import post
import urllib.request
from urllib.error import URLError
from time import sleep
import threading
url = "http://10.255.0.19/a79.htm" #学校认证地址
print("----------------AUST-认证脚本------------------")
user = input("学号:") #你的学号
password = input("密码:") #你的密码
server = input("\n电信:aust\n联通:unicom\n移动:cmcc\n运营商: ") #电信aust 联通改为 unicom 移动改为 cmcc
#发送的数据包
data = {
"callback": "dr1003",
"DDDDD": "{}@{}".format(user, server),
"upass": "{}".format(password),
"0MKKey": "123456",
"R1": "0",
"R3": "0",
"R6": "0",
"para": "00",
"v6ip": "",
"v": ""
}
# 标志变量用于控制线程的执行
stop_flag = False
#检查是否连接到外部网络
def check_internet_connection():
try:
url = 'https://www.baidu.com'
headers = {'User-Agent': 'Mozilla/5.0', 'Content-Length': '1'} # Modify the Content-Length header value as needed
req = urllib.request.Request(url, headers=headers)
urllib.request.urlopen(req, timeout=1)
return True
except URLError:
return False
#检查用户输入,并判断是否退出程序
def user_input_thread():
while True:
global stop_flag #引入全局变量
user_input = input() # 获取用户输入
if (user_input.lower() == "q"):
stop_flag = True #标志置是
break #退出循环
# 创建一个线程来处理用户输入
input_thread = threading.Thread(target=user_input_thread)
input_thread.start()
#主函数(执行检测,并判断发送数据包)
while not stop_flag:
if check_internet_connection():
print("\r已连接到Internet", end = ' ')
#pass
else:
print("未连接到Internet, 正在尝试重新连接...")
conn = post(url=url, data=data) #发送数据包
sleep(1) # 每隔1秒进行一次检测
import requests
import urllib.request
import time
import threading
url = "http://10.255.0.41/0.htm" #学校认证地址
print("----------------AUST-认证脚本------------------")
# user = input("学号:") #你的学号
# password = input("密码:") #你的密码
# server = input("\n电信:aust\n联通:unicom\n移动:cmcc\n运营商: ") #电信aust 联通改为 unicom 移动改为 cmcc
#发送的数据包
data = {
"DDDDD":"",
"upass":"",
"0MKKey":"%B5%C7%A1%A1%C2%BC",
"v6ip":""
}
# 标志变量用于控制线程的执行
stop_flag = False
#检查是否连接到外部网络
def check_internet_connection():
try:
url = 'https://www.baidu.com'
headers = {'User-Agent': 'Mozilla/5.0', 'Content-Length': '1'} # Modify the Content-Length header value as needed
req = urllib.request.Request(url, headers=headers)
urllib.request.urlopen(req, timeout=1)
return True
except urllib.error.URLError:
return False
#检查用户输入,并判断是否退出程序
def user_input_thread():
while True:
global stop_flag #引入全局变量
user_input = input() # 获取用户输入
if (user_input.lower() == "q"):
stop_flag = True #标志置是
break #退出循环
# 创建一个线程来处理用户输入
input_thread = threading.Thread(target=user_input_thread)
input_thread.start()
#主函数(执行检测,并判断发送数据包)
while not stop_flag:
if check_internet_connection():
print("已连接到Internet")
#pass
else:
print("未连接到Internet")
print("正在尝试重新连接...")
conn = requests.post(url=url, data=data) #发送数据包
time.sleep(2) # 每隔2秒进行一次检测
/** Comments(0)*/
Loading comments...