上网需要账号认证,而且在凌晨系统就会自动将账号踢下线。


一家叫Sangfor做的客户端,不安它就上不了网。
需要远程查看设备状态,掉线了就连不进来了。找人去申请长时间在线,结果是1天1掉线,之前还是两天1掉线。
基础的东西要告诉ai,然后让它用python编个程序检查。
登录网址
填个错误的密码,点提交,用F12查看得到地址。
RC4 加密
分析网页里的js代码,找出来让ai改。
运行效果:

源代码
python
import asyncio
import time
import aiohttp
import json
from colorama import Fore, Back, Style, init
from datetime import datetime
init(autoreset=True)
# ================= 配置区域 =================
# 请在此处修改实际的登录地址、用户名和密码
LOGIN_URL = "http://192.0.1.1/ac_portal/login.php"
USERNAME = "fuyaozhishang9wanli"
PASSWORD = "*******"
# 时间配置 (单位:秒)
CHECK_INTERVAL_NORMAL = 300 # 正常检查间隔:300秒
CHECK_INTERVAL_RETRY = 100 # 重试间隔:100秒
NETWORK_CHECK_URL = "https://www.baidu.com"
# ===========================================
def do_encrypt_rc4(src, passwd):
"""
RC4 加密函数 (同步函数,执行非常快,不影响异步性能)
"""
src_str = str(src).strip()
passwd_str = str(passwd)
key = [0] * 256
sbox = list(range(256))
plen = len(passwd_str)
size = len(src_str)
for i in range(256):
key[i] = ord(passwd_str[i % plen])
j = 0
for i in range(256):
j = (j + sbox[i] + key[i]) % 256
sbox[i], sbox[j] = sbox[j], sbox[i]
output = []
a = 0
b = 0
for i in range(size):
a = (a + 1) % 256
b = (b + sbox[a]) % 256
sbox[a], sbox[b] = sbox[b], sbox[a]
c = (sbox[a] + sbox[b]) % 256
k = sbox[c]
char_code = ord(src_str[i])
temp = char_code ^ k
hex_str = format(temp, 'x')
if len(hex_str) == 1:
hex_str = '0' + hex_str
elif len(hex_str) == 0:
hex_str = '00'
output.append(hex_str)
return ''.join(output)
def get_current_time():
"""获取当前格式化时间"""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
async def check_network(session):
"""
异步检查网络是否正常 (通过访问百度)
返回: True (正常) / False (异常)
"""
try:
# 设置较短的超时时间,避免长时间等待
async with session.get(NETWORK_CHECK_URL, timeout=aiohttp.ClientTimeout(total=10)) as response:
if response.status == 200:
return True
return False
except Exception as e:
# 打印简短的错误信息供调试,但不阻断流程
# print(f" [调试] 网络检查异常: {e}")
return False
async def do_login(session):
"""
执行异步登录操作
返回: True (登录成功) / False (登录失败)
"""
print(f"[{get_current_time()}] >>> 正在尝试登录认证...")
# 1. 生成加密数据
rckey = str(int(time.time() * 1000))
encrypted_pwd = do_encrypt_rc4(PASSWORD, rckey)
payload = {
'opr': 'pwdLogin',
'userName': USERNAME,
'pwd': encrypted_pwd,
'auth_tag': rckey,
'rememberPwd': '1'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
try:
async with session.post(LOGIN_URL, data=payload, headers=headers, timeout=aiohttp.ClientTimeout(total=10)) as response:
# 先获取 HTTP 状态码
if response.status == 200:
# 【核心修改】:先获取文本内容,而不是直接 json()
# response.text() 返回的是字符串
text_content = await response.text()
# 尝试解析为 JSON (兼容原逻辑)
try:
data = json.loads(text_content) # 使用 json.loads 解析字符串
print(f'响应内容:{text_content}')
if data.get('success'):
print(f"{Back.GREEN}[{get_current_time()}] √ 登录成功!")
return True
else:
print(f"{Back.RED}[{get_current_time()}] x 登录失败: {data.get('msg', '服务器返回错误')}")
return False
except (json.JSONDecodeError, ValueError):
# 【核心修改】:如果不是 JSON,执行这里的逻辑
# 情况 A: 服务器可能直接返回了一个 URL 字符串
# 判断是否包含 http (简单判断)
if 'http' in text_content and len(text_content) < 200:
print(f"[{get_current_time()}] √ 登录成功 (服务器返回URL: {text_content})")
# 如果需要跳转,可以在这里处理 text_content
return True
# 情况 B: 服务器返回了 HTML 网页 (例如直接跳转到了首页)
# 可以通过判断是否包含 </html> 或特定关键字
elif 'homepage' in text_content or 'index' in text_content:
print(f"[{get_current_time()}] √ 登录成功 (服务器返回了网页内容)")
return True
# 情况 C: 未知的文本内容
else:
print(f"[{get_current_time()}] x 登录失败: 服务器返回非JSON数据")
# 打印前100个字符方便调试
print(f" 返回内容摘要: {text_content[:100]}...")
return False
else:
print(f"[{get_current_time()}] x 登录失败: HTTP状态码 {response.status}")
return False
except Exception as e:
print(f"[{get_current_time()}] x 登录请求异常: {e}")
return False
async def main_loop():
"""
主控制循环
"""
print(f"[{get_current_time()}] 程序启动,初始化会话...")
# 使用 aiohttp.ClientSession 保持会话
async with aiohttp.ClientSession() as session:
while True:
# 1. 检查网络状态
# print(f"[{get_current_time()}] 正在进行网络连通性检查")
is_net_ok = await check_network(session)
if is_net_ok:
print(f"{Fore.GREEN}[{get_current_time()}] 网络正常。")
# 网络正常,休眠后进行下一次检查
wait_time = CHECK_INTERVAL_NORMAL
else:
# 网络异常,尝试登录
print(f"[{get_current_time()}] ⚠ 网络异常!")
login_success = await do_login(session)
if login_success:
# 登录成功,恢复正常检查周期
wait_time = CHECK_INTERVAL_NORMAL
else:
# 登录失败,进入快速重试周期 (5分钟)
print(f"[{get_current_time()}] 将在 5 分钟后重试...")
wait_time = CHECK_INTERVAL_RETRY
# 2. 异步休眠,不阻塞系统
# 使用 asyncio.sleep 而不是 time.sleep
print(f"[{get_current_time()}] 等待 {wait_time/60:.0f} 分钟后进行下一次任务...")
await asyncio.sleep(wait_time)
if __name__ == "__main__":
try:
# 运行异步主循环
asyncio.run(main_loop())
except KeyboardInterrupt:
print(f"\n[{get_current_time()}] 用户手动停止程序。")
注:
代码问智谱4.7写的.