【发布时间】:2013-08-14 09:07:48
【问题描述】:
想象一下,你有 Windows 7,文件“passwords.txt”,其中包含 2000 个 Wifi 密码“MyHomeWifi”,但只有一个是正确的。你有蟒蛇。当然,问题是如何连接到这个 wifi。 我只知道,要连接到 wifi,你可以在命令行中使用:
netsh wlan connect _Wifi_name_
【问题讨论】:
想象一下,你有 Windows 7,文件“passwords.txt”,其中包含 2000 个 Wifi 密码“MyHomeWifi”,但只有一个是正确的。你有蟒蛇。当然,问题是如何连接到这个 wifi。 我只知道,要连接到 wifi,你可以在命令行中使用:
netsh wlan connect _Wifi_name_
【问题讨论】:
from subprocess import check_output
output = check_output('netsh wlan connect _Wifi_name_', shell=True)
print output
剩下的就看你自己了。 考虑合并以下内容(你必须自己做一些工作......):
with open('mypasswords.txt') as fh:
for line in fh:
...
实用地“写入”密码作为通过 python 的输入,而不是将其作为参数传递:
from subprocess import Popen, STDOUT, PIPE
from time import sleep
handle = Popen('netsh wlan connect _Wifi_name_', shell=True, stdout=PIPE, stderr=STDOUT, stdin=PIPE)
sleep(5) # wait for the password prompt to occur (if there is one, i'm on Linux and sudo will always ask me for a password so i'm just assuming windows isn't retarded).
handle.stdint.write('mySecretP@ssW0rd\n')
while handle.poll() == None:
print handle.stdout.readline().strip()
一个更受控制的版本。
【讨论】: