Connection to wi-fi using python

12,985
from subprocess import check_output
output = check_output('netsh wlan connect _Wifi_name_', shell=True)

print output

The rest is up to you. Consider merging in the following (you gotta do some work yourself man..):

with open('mypasswords.txt') as fh:
    for line in fh:
        ...

Pragmatically "writing" passwords as input via python instead of passing it as a parameter:

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()

A more controlled version of it.

Share:
12,985
PepeHands
Author by

PepeHands

Updated on June 28, 2022

Comments

  • PepeHands
    PepeHands almost 2 years

    Imagine, you have Windows 7, file "passwords.txt", which contains 2000 passwords for Wifi "MyHomeWifi", but only one of them is correct. And you have python. And, of course, the question is how to connect to this wifi. I only know, that to connect to wifi you can use in command line:

    netsh wlan connect _Wifi_name_