Posts: 26
Joined: Thu Jan 25, 2018 8:23 pm

Connect to internet using a python script/commandline

Fri Sep 14, 2018 11:33 pm

I have a Raspberry-Pi zero w and I want to connect it to the internet using a python script. I know the network ESSID and Password. Is there any python library that can do this?
Is there any way I can do it via command line? If there is, I can use the subprocess library to execute that command. I have used the following command but it doesnt seem to work:

sudo iwconfig wlan0 essid NETWORKID key s:PASSWORD

if seems to run successfully without any errors but it doesn't connect the raspberry-pi to the internet.

I know I can use nmcli, but for some reason, I am avoiding it. Is there any other way I can connect to the internet using a python script/commandline?

User avatar
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Connect to internet using a python script/commandline

Sat Sep 15, 2018 8:27 am

Take a look at rewriting your /etc/wpa_supplicant/wpa_supplicant.conf with the wpa_passphrase command

sudo sh -c "wpa_passphrase SSID password >> /etc/wpa_supplicant/wpa_supplicant.conf"

If you then kill and restart wpa_supplicant it will connect to the network you've just defined.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

Return to “General discussion”