2

Is there some way I can detect available WiFi networks, which are open, using Python? I know I can do it on my Ubuntu box, but I haven't received my Pi yet, so I haven't been able to run the same code on it.

Thanks!

PS - Here's the code I use on Ubuntu.

from gi.repository import NetworkManager, NMClient
nmc = NMClient.Client.new()
devs = nmc.get_devices()
for dev in devs:
 if dev.get_device_type() == NetworkManager.DeviceType.WIFI:
 for ap in dev.get_access_points():
 print ap.get_ssid()
asked May 29, 2013 at 2:41

2 Answers 2

0

there's no module 'gi' installed on raspi by default, but nobody can stop you from installing it manually. other than that, there's a nice command iwlist that shows a lot of information about available networks, so I suppose in the unlikely event you cannot install 'gi' on raspberry, you may just run iwlist from python and catch/parse the output.

answered May 29, 2013 at 10:09
1
  • Ah, nice! Well. Gotta wait for another week before I get my Pi. Thanks a ton! Commented May 30, 2013 at 18:17
0

I have come to the code below that works for me, on a Pi 4 using Python 3.7.

# os.popen(): https://www.tutorialspoint.com/python3/os_popen.htm
networks= os.popen('sudo iwlist wlan0 scanning | grep ESSID').read()
# Parse all found networks list in a clean list 'networkslist'
networkslist= re.findall(r'"(.+?)"', networks)
# Print all networks to a list on screen
self.window.networklistview.addItems(networkslist)

It uses iwlist and makes a list available on the variable networklist. Regex is used to extract useful info. The last line offerst networklist to a list viewer from Qt. Some insight came from here Wi-Fi scanning and displaying using Python run by PHP

answered Mar 28, 2023 at 18:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.