How to Build a WiFi Scanner in Python?

By | May 6, 2021

WiFi is an abbreviation for Wireless-Fidelity, and as its name suggests it is a wireless technology that allows computers and other mobile and electronic devices to connect through the internet or any other network.

Although all the devices which are capable to connect through wifi come with GUI that shows all the available wifi networks in the surrounding. But it would be cool to know how can you list out all the available wifi networks using Python script. And in this Python tutorial, you will learn how to do so. In this tutorial, you will learn how to build a Python wifi scanner with few lines of Python code.

Vamware

For this tutorial we will not be using any third-party packages, instead, we will use the Python inbuilt subprocess module.

Python program to build a Wifi Scanner

import subprocess

#return all the available network
networks = subprocess.check_output(['netsh', 'wlan', 'show', 'network'])

decoded_networks = networks.decode('ascii')

print(decoded_networks)

Output

Interface name : Wi-Fi 

There are 1 networks currently visible. 

SSID 1 : one plus7t

    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP 

Behind the code

The check_output() the function is used to run a terminal command specified as an argument list and return its output.

'netsh' stand for network shell and it is a command-line utility that is used to modify and display the network configuration of the system.

'wlan'the argument specifies the wireless network.

'show' will return display the available 'network'.

decode('ascii') the function will decode the encoded check_output() the function returned networks.

Using our Python script we are simply running the netsh command-line utility and displaying all the available networks. We can also use the same command on our terminal or command prompt to show all the available networks.

netsh wlan show network

Conclusion

In my case, only one wifi network is available in the surrounding that’s why in output I am getting 1 network available. To make this tutorial simple and straightforward I have used the inbuilt Python subprocesses module. There is a Python powerful third part package called scapy that is also capable of building a wifi scanner.

If you are into ethical hacking and networking with Python you can also check out our other Python tutorials on How to make a port scanner in Python, and how to make a chat room in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *