feat: allow run without -i,--interface given
This commit is contained in:
+30
-14
@@ -3,6 +3,7 @@ import json
|
|||||||
import random
|
import random
|
||||||
import subprocess
|
import subprocess
|
||||||
import syslog
|
import syslog
|
||||||
|
import warnings
|
||||||
|
|
||||||
def print(*a, sep=' '): syslog.syslog(sep.join(map(str, a)))
|
def print(*a, sep=' '): syslog.syslog(sep.join(map(str, a)))
|
||||||
|
|
||||||
@@ -10,14 +11,22 @@ import argparse
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-i", "--interface", help="网卡接口名称 interface")
|
parser.add_argument("-i", "--interface", help="网卡接口名称 interface")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
interface = args.interface
|
||||||
|
interface_def = interface is None
|
||||||
|
|
||||||
def request_get_text(url, headers={}):
|
def request_get_text(url, headers={}):
|
||||||
req = request.Request(url, headers=headers)
|
req = request.Request(url, headers=headers)
|
||||||
with request.urlopen(req) as response:
|
with request.urlopen(req) as response:
|
||||||
return response.read().decode('utf-8')
|
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):
|
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:
|
try:
|
||||||
result = subprocess.check_call(command, timeout=2)
|
result = subprocess.check_call(command, timeout=2)
|
||||||
return result == 0
|
return result == 0
|
||||||
@@ -31,10 +40,8 @@ def check_connectivity_ping(host, interface):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
device = 0
|
device = 0
|
||||||
interface = args.interface
|
if interface_def:
|
||||||
if interface is None:
|
warnings.warn("no interface given by -i or --interface, use default route")
|
||||||
print("Please specify the interface name using -i or --interface")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# 检测网络联通性
|
# 检测网络联通性
|
||||||
if check_connectivity_ping("223.5.5.5", interface):
|
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 = []
|
user_pwd_error_or_not_unlimit_combo = []
|
||||||
# 检查是否付费
|
# 检查是否付费
|
||||||
while True:
|
not_succ = True
|
||||||
|
while not_succ:
|
||||||
# 随机选择,防止前面有密码错误的用户卡死
|
# 随机选择,防止前面有密码错误的用户卡死
|
||||||
user, pwd = random.choice(user_pwd)
|
user, pwd = random.choice(user_pwd)
|
||||||
if user in user_pwd_error_or_not_unlimit_combo:
|
if user in user_pwd_error_or_not_unlimit_combo:
|
||||||
@@ -70,24 +78,32 @@ while True:
|
|||||||
if int(j1['count']) == device:
|
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"
|
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"
|
||||||
command = ["curl", url, "--interface", interface]
|
if interface_def:
|
||||||
result = subprocess.run(command, capture_output=True, text=True)
|
res = request_get_text(url)
|
||||||
result = json.loads(result.stdout[7:-2])
|
else:
|
||||||
|
command = ["curl", url, "--interface", interface]
|
||||||
|
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":0,"msg":"密码错误","ret_code":1});
|
dr1003({"result":0,"msg":"密码错误","ret_code":1});
|
||||||
dr1003({"result":1,"msg":"Portal协议认证成功!"});
|
dr1003({"result":1,"msg":"Portal协议认证成功!"});
|
||||||
dr1003({"result":0,"msg":"IP: 10.142.5.160 已经在线!","ret_code":2});
|
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']:
|
if '密码错误' in result['msg']:
|
||||||
print(f"接口 {interface}: {user} {pwd} 密码错误")
|
print(f"{user} {pwd} 密码错误")
|
||||||
user_pwd_error_or_not_unlimit_combo.append(user)
|
user_pwd_error_or_not_unlimit_combo.append(user)
|
||||||
elif '已经在线' in result['msg']:
|
elif '已经在线' in result['msg']:
|
||||||
print(f"接口 {interface}: 正常在线!")
|
msg += "正常在线!"
|
||||||
break
|
not_succ = False
|
||||||
elif '认证成功' in result['msg']:
|
elif '认证成功' in result['msg']:
|
||||||
print(f"接口 {interface}:使用账号{user}登录成功!")
|
msg += f"使用账号{user}登录成功!"
|
||||||
break
|
not_succ = False
|
||||||
|
print(msg)
|
||||||
else:
|
else:
|
||||||
user_pwd_error_or_not_unlimit_combo.append(user)
|
user_pwd_error_or_not_unlimit_combo.append(user)
|
||||||
# 删除密码错误或不满足要求的用户
|
# 删除密码错误或不满足要求的用户
|
||||||
|
|||||||
Reference in New Issue
Block a user