feat: add -f,--file; fix hardcoded /root/user_pwd

This commit is contained in:
lit
2025-06-24 16:46:22 +08:00
parent 23668e8e98
commit 5f7aff7d1b
+5 -2
View File
@@ -10,8 +10,11 @@ def print(*a, sep=' '): syslog.syslog(sep.join(map(str, a)))
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-i", "--interface", help="网卡接口名称 interface") parser.add_argument("-i", "--interface", help="网卡接口名称 interface")
parser.add_argument("-f", "--file", help="用户密码文件路径", default="user_pwd.txt")
args = parser.parse_args() args = parser.parse_args()
interface = args.interface interface = args.interface
file = args.file
interface_def = interface is None interface_def = interface is None
def request_get_text(url, headers={}): def request_get_text(url, headers={}):
@@ -47,7 +50,7 @@ if interface_def:
if check_connectivity_ping("223.5.5.5", interface): if check_connectivity_ping("223.5.5.5", interface):
exit() exit()
with open("user_pwd.txt", 'r') as f: with open(file, 'r') as f:
user_pwd = [i.rstrip('\n\r').split() for i in f.readlines()] user_pwd = [i.rstrip('\n\r').split() for i in f.readlines()]
user_pwd_error_or_not_unlimit_combo = [] user_pwd_error_or_not_unlimit_combo = []
@@ -109,5 +112,5 @@ while not_succ:
# 删除密码错误或不满足要求的用户 # 删除密码错误或不满足要求的用户
if user_pwd_error_or_not_unlimit_combo: if user_pwd_error_or_not_unlimit_combo:
sed_i_arg = '/^' + '\\|^'.join(user_pwd_error_or_not_unlimit_combo) + '/d' sed_i_arg = '/^' + '\\|^'.join(user_pwd_error_or_not_unlimit_combo) + '/d'
cmd = ['sed','-i', sed_i_arg, '/root/user_pwd.txt'] cmd = ['sed','-i', sed_i_arg, file]
subprocess.run(cmd) subprocess.run(cmd)