Reputation: 77
I am trying to scan all available wifi devices using python. I wrote below code to get SSID,BSSID and device information
results = subprocess.check_output(["sudo", "nmcli", "-f", "SSID", "BSSID", "DEVICE", "dev", "wifi"])
But it is giving me error- "bssid not understood"
when I run the below command in terminal it is working fine.
sudo nmcli -f SSID,BSSID,DEVICE dev wifi
If I remove BSSID and DEVICE then it is working fine. And I am getting all the ssids
results = subprocess.check_output(["sudo", "nmcli", "-f", "SSID", "dev", "wifi"])
I could not understand what is going wrong.
I am using
Python-3.6.8
Ubuntu-18.04.2 LTS
Upvotes: 1
Views: 524
Reputation: 46859
you need to pass the arguments as
["sudo", "nmcli", "-f", "SSID,BSSID,DEVICE", "dev", "wifi"]
if the last command line really works. note that there is one argument "SSID,BSSID,DEVICE"
.
you could also generate the list using shlex
:
import shlex
args = shlex.split("sudo nmcli -f SSID,BSSID,DEVICE dev wifi")
# ['sudo', 'nmcli', '-f', 'SSID,BSSID,DEVICE', 'dev', 'wifi']
Upvotes: 2