# -*- coding: utf-8 -*- """验证 MySQL / Redis 连通性与密码候选值""" import socket import pymysql CANDIDATES = ["@//qinys12346..", "@ @//qinys12346..", "@ @//qinys12346../", "@//qinys12346../", "@ @//qinys12346../"] print("=== MySQL 192.168.1.177:3306 ===") for pwd in CANDIDATES: try: conn = pymysql.connect(host="192.168.1.177", port=3306, user="root", password=pwd, database="shop", connect_timeout=5) with conn.cursor() as c: c.execute("SELECT VERSION()") ver = c.fetchone()[0] c.execute("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='shop'") tables = c.fetchone()[0] conn.close() print(f"[OK] 密码={pwd!r} MySQL {ver}, shop 库表数量={tables}") break except Exception as e: print(f"[FAIL] 密码={pwd!r} -> {e}") print("=== Redis 192.168.1.177:6379 ===") def redis_test(pwd): s = socket.create_connection(("192.168.1.177", 6379), timeout=5) def cmd(*args): line = f"*{len(args)}\r\n".encode() for a in args: b = a.encode() line += f"${len(b)}\r\n".encode() + b + b"\r\n" s.sendall(line) return s.recv(200) if pwd: r = cmd("AUTH", pwd) if not r.startswith(b"+OK"): s.close() return f"AUTH失败: {r!r}" r = cmd("PING") s.close() return r for pwd in CANDIDATES: res = redis_test(pwd) if b"PONG" in str(res).encode() or res == b"+PONG\r\n": print(f"[OK] 密码={pwd!r} PING->PONG") break print(f"[FAIL] 密码={pwd!r} -> {res!r}")