Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpa_supplicant - how to switch to different network?

What I need: Connect to different wifi network on archlinux by calling python script.

What I am doing: Executing the following statements from python:

wpa_passphrase "MySSID" "MyPass"> /etc/wpa_supplicant/profile.conf
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/profile.conf
dhcpd wlan0

It works only for the first attempt. When it is executed the second time, it says dhcpd is already on. I dont know how to switch to another network.

I have also tried wpa_cli and again, dont know how to switch to another network.

Please suggest some fix or alternatives (uncomplicated)

like image 255
Dushyant Bangal Avatar asked Nov 09 '22 20:11

Dushyant Bangal


1 Answers

Your concrete Problem is that you start wpa_supplicant and dhcp instead of re-starting them. I have a script that reads

#shutdown dhc
dhclient -r
#shutdown wpa_supplicant
killall wpa_supplicant
#down interface
ifdown --force wlan0
sleep 1
#your wpa startup here:
wpa_supplicant -t -fYOUR_LOG_FILE -cYOUR_wpa_supplicant.conf -B -iwlan0
sleep 1
#restart dhc
dhclient -nw

I guess you can do this a little more nicely by configuring your /etc/network/interfaces appropriately.

Btw. in principle, it should not be necessary to restart the dhc at all. After some while it should realize that it needs to fetch a new IP, but for me this takes to long. ;)

like image 176
Echsecutor Avatar answered Nov 14 '22 21:11

Echsecutor