from flask import Flask, render_template_string import os from pathlib import Path import threading import time import subprocess import sys app = Flask(__name__) # 全局变量 is_running = False failed_count = 0 success_results = [] process = None # 读取成功结果 def load_success_results(): success_file = Path("success.txt") if success_file.exists(): with open(success_file, 'r', encoding='utf-8') as f: return f.readlines() return [] # 启动破解程序 def start_bruteforce(): global is_running, process is_running = True try: # 直接运行jms.py作为子进程 process = subprocess.Popen( [sys.executable, "jms.py"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True ) # 实时读取输出 for line in iter(process.stdout.readline, ''): if not is_running: break # 解析尝试次数 if "已尝试次数:" in line: try: global failed_count failed_count = int(line.split("已尝试次数: ")[1].strip()) except: pass # 解析成功结果 if "匹配成功:" in line: success_results.append(line.strip()) # 写入文件 with open("success.txt", 'a', encoding='utf-8') as f: f.write(line.strip() + '\n') process.wait() except Exception as e: print(f"运行错误: {e}") finally: is_running = False # 主页路由 @app.route('/') def index(): global is_running, failed_count, success_results success_results = load_success_results() html = """
已尝试次数: {{ failed_count }}
{% if not is_running %} {% endif %}{{ result.strip() }}
{% endfor %}
{% else %}
暂无匹配结果
{% endif %}