How to Build a WiFi Scanner in Python?

By | December 27, 2021

Wi-fi is an abbreviation for wireless-fidelity. It is a wireless technology that allows computers, mobiles, and digital devices to connect to the internet or any other network. This tutorial explains how to build a wifi scanner in Python.

All the devices that are capable of connecting to wifi come with GUI that shows all the available wifi networks in the surroundings. But wouldn’t it be cool to know how to list all the available wifi networks using a Python script? And in this Python tutorial, you will learn how to do so. In this tutorial, you will learn how to build a wifi scanner in Python with only a few lines of code.

For this Python tutorial, we will not use any third-party packages. Instead, we will use the inbuilt subprocess module. However, you can try the program using different third-party packages once you get the gist of building a Wi-Fi scanner using Python code.

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() function is used to run a terminal command specified as an argument list and return its output.
  • 'netsh' stands for network shell, and it is a command-line utility that is used to modify and display the network configuration of the system.
  • The 'wlan' argument specifies the wireless network.
  • 'show' will display the available 'network'.
  • The decode('ascii') function will decode the encoded check_output() function returned networks.

Using this 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

In our case, only one wifi network is available, and that’s why in the output, we are getting only 1 network available. However, if you will have many networks, all of them will appear in the output.

Vamware

Conclusion

To make this tutorial simple and straightforward, we have used the inbuilt Python subprocesses module. Nonetheless, there is a powerful third-party Python package called scapy that is also capable of building a wifi scanner.

If you are into ethical hacking and networking with Python, consider checking out our other Python tutorials on How to make a port scanner in Python? and How to make a chat room in Python?

People are also reading: 

One thought on “How to Build a WiFi Scanner in Python?

Leave a Reply

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