Connect Wifi with Python or Linux Terminal

How can i turn on wifi connection using python?

If you want to set up a Hotspot, you need to enable monitor mode of the WiFi driver.
If you're on linux you can do,

ifconfig and iwconfig to find the name of WiFi driver/device
and then use one of the air suite package to turn on the monitor mode on that particular driver

airmon-ng start <driver name>

All these commands can be run using the python subprocess module, which allows you to interact with the linux/windows command line to process output and work out accordingly

import subprocess
p = subprocess.Popen(["echo", "hello world"], stdout=subprocess.PIPE)

print(p.communicate())

>>>('hello world', None)

Connection to wi-fi using python

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.



Related Topics



Leave a reply



Submit