To get wifi list, parse the output of nmcli dev wifi list
import subprocess
def scan():
subprocess.call(['nmcli', 'dev', 'wifi', 'rescan'])
output = subprocess.check_output(['nmcli', 'dev', 'wifi', 'list'])
ap_list = []
for row in output.split('\n')[1:-1]:
items = row.split()
ap = items[0]
if ap == '*':
ap = items[1]
ap_list.append(ap)
return ap_list
Use python-networkmanager
Run sudo apt-get install libdbus-glib-1-dev and sudo pip install python-networkmanager, then
import NetworkManager
for dev in NetworkManager.NetworkManager.GetDevices():
if dev.DeviceType != NetworkManager.NM_DEVICE_TYPE_WIFI:
continue
for ap in dev.GetAccessPoints():
print('%-30s %dMHz %d%%' % (ap.Ssid, ap.Frequency, ap.Strength))
To connect to an AP, run nmcli dev wifi connect YOUR-AP password YOUR-PASSWORD.
nmcli
To get wifi list, parse the output of
nmcli dev wifi list
Run
sudo apt-get install libdbus-glib-1-dev
andsudo pip install python-networkmanager
, thenTo connect to an AP, run
nmcli dev wifi connect YOUR-AP password YOUR-PASSWORD
.