1

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"

enter image description here

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

1 Answer 1

2

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']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.