feat: allow run without -i,--interface given
This commit is contained in:
+29
-13
@@ -3,6 +3,7 @@ import json
|
||||
import random
|
||||
import subprocess
|
||||
import syslog
|
||||
import warnings
|
||||
|
||||
def print(*a, sep=' '): syslog.syslog(sep.join(map(str, a)))
|
||||
|
||||
@@ -10,14 +11,22 @@ import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-i", "--interface", help="网卡接口名称 interface")
|
||||
args = parser.parse_args()
|
||||
interface = args.interface
|
||||
interface_def = interface is None
|
||||
|
||||
def request_get_text(url, headers={}):
|
||||
req = request.Request(url, headers=headers)
|
||||
with request.urlopen(req) as response:
|
||||
return response.read().decode('utf-8')
|
||||
|
||||
def append_interface(command, pre, interface):
|
||||
if not interface_def:
|
||||
command += [pre, interface]
|
||||
|
||||
def check_connectivity_ping(host, interface):
|
||||
command = ['ping', '-I', interface, '-c', '1', host] # -n 1 on windows, -c 1 on linux
|
||||
command = ['ping']
|
||||
append_interface(command, '-I', interface)
|
||||
command += ['-c', '1', host] # -n 1 on windows, -c 1 on linux
|
||||
try:
|
||||
result = subprocess.check_call(command, timeout=2)
|
||||
return result == 0
|
||||
@@ -31,10 +40,8 @@ def check_connectivity_ping(host, interface):
|
||||
return False
|
||||
|
||||
device = 0
|
||||
interface = args.interface
|
||||
if interface is None:
|
||||
print("Please specify the interface name using -i or --interface")
|
||||
exit()
|
||||
if interface_def:
|
||||
warnings.warn("no interface given by -i or --interface, use default route")
|
||||
|
||||
# 检测网络联通性
|
||||
if check_connectivity_ping("223.5.5.5", interface):
|
||||
@@ -45,7 +52,8 @@ with open("user_pwd.txt", 'r') as f:
|
||||
|
||||
user_pwd_error_or_not_unlimit_combo = []
|
||||
# 检查是否付费
|
||||
while True:
|
||||
not_succ = True
|
||||
while not_succ:
|
||||
# 随机选择,防止前面有密码错误的用户卡死
|
||||
user, pwd = random.choice(user_pwd)
|
||||
if user in user_pwd_error_or_not_unlimit_combo:
|
||||
@@ -70,24 +78,32 @@ while True:
|
||||
if int(j1['count']) == device:
|
||||
# 判断密码是否正确
|
||||
url = f"https://xha.ouc.edu.cn:802/eportal/portal/login?callback=dr1003&login_method=1&user_account={user}&user_password={pwd}&wlan_user_ip=0.0.0.0&wlan_user_ipv6=&wlan_user_mac=000000000000&wlan_ac_ip=&wlan_ac_name=&jsVersion=4.1&terminal_type=1&lang=zh-cn&v=2425&lang=zh"
|
||||
if interface_def:
|
||||
res = request_get_text(url)
|
||||
else:
|
||||
command = ["curl", url, "--interface", interface]
|
||||
result = subprocess.run(command, capture_output=True, text=True)
|
||||
result = json.loads(result.stdout[7:-2])
|
||||
res = subprocess.check_output(command, text=True)
|
||||
result = json.loads(res[7:-2])
|
||||
"""
|
||||
dr1003({"result":0,"msg":"账号不存在","ret_code":1});
|
||||
dr1003({"result":0,"msg":"密码错误","ret_code":1});
|
||||
dr1003({"result":1,"msg":"Portal协议认证成功!"});
|
||||
dr1003({"result":0,"msg":"IP: 10.142.5.160 已经在线!","ret_code":2});
|
||||
"""
|
||||
msg = ""
|
||||
if not interface_def:
|
||||
print(f"使用接口 {interface} 进行请求")
|
||||
msg += f"接口 {interface}: "
|
||||
if '密码错误' in result['msg']:
|
||||
print(f"接口 {interface}: {user} {pwd} 密码错误")
|
||||
print(f"{user} {pwd} 密码错误")
|
||||
user_pwd_error_or_not_unlimit_combo.append(user)
|
||||
elif '已经在线' in result['msg']:
|
||||
print(f"接口 {interface}: 正常在线!")
|
||||
break
|
||||
msg += "正常在线!"
|
||||
not_succ = False
|
||||
elif '认证成功' in result['msg']:
|
||||
print(f"接口 {interface}:使用账号{user}登录成功!")
|
||||
break
|
||||
msg += f"使用账号{user}登录成功!"
|
||||
not_succ = False
|
||||
print(msg)
|
||||
else:
|
||||
user_pwd_error_or_not_unlimit_combo.append(user)
|
||||
# 删除密码错误或不满足要求的用户
|
||||
|
||||
Reference in New Issue
Block a user