Search code examples
pythonpython-3.xsocketsnetwork-programmingwifi

How to find all and connect all available wifi signals using python?


I am working raspberry pi to find and connect all available wifi connections. How can I find and list all WIFI Networks available using python. Can we print all available wifi connections by using python sockets. If sockets can't do this job then which library can we use to do so?


Solution

  • I think one of the best modules for wifi manipulation in python is the wifi package.

    pip install wifi

    Simple use case is; (replace "wlan0" with your wireless device id)

    from wifi import Cell, Scheme
    list(Cell.all('wlan0'))
    

    This will return a list of Cell objects. Each object will have the following attributes:

    • ssid
    • signal
    • quality
    • frequency
    • bitrates
    • encrypted
    • channel
    • address
    • mode

    For cells that have encrypted as True, there will also be the following attributes:

    • encryption_type

    To connenc to an AP;

    cell = list(Cell.all('wlan0'))[0]
    scheme = Scheme.for_cell('wlan0', 'home', cell, passkey)
    scheme.save()
    scheme.activate()
    
    scheme = Scheme.find('wlan0', 'home')
    scheme.activate()
    

    for more info goto https://wifi.readthedocs.io/en/latest/