Open In App

How to Build a WiFi Scanner in Python using Scapy?

In this article, we are going to build a WiFi Scanner in Python using Scapy. WiFi Scanning or Network scanning refers to the scanning of the whole network to which we are connected and try to find out what are all the clients connected to our network. We can identify each client using their IP and MAC address. We can use ARP ping to find out the alive systems in our network.

The network scanner will send the ARP request indicating who has some specific IP address, let’s say “192.168.1.1”, the owner of that IP address ( the target ) will automatically respond saying that he is “192.168.1.1”, with that response, the MAC address will also be included in the packet, this allows us to successfully retrieve all network users’ IP and MAC addresses simultaneously when we send a broadcast packet ( sending a packet to all the devices in the network ).



Some important functions for creating a Network scanner:

we will create an ARP packet and the with the help of ls() function, we will see what are the available fields for this packet.



Approach:

Below is the Python implementation:




import scapy.all as scapy 
  
request = scapy.ARP() 
    
request.pdst = '192.168.0.1/24'
broadcast = scapy.Ether() 
    
broadcast.dst = 'ff:ff:ff:ff:ff:ff'
    
request_broadcast = broadcast / request 
clients = scapy.srp(request_broadcast, timeout = 10,verbose = 1)[0
for element in clients: 
    print(element[1].psrc + "      " + element[1].hwsrc) 

Output:

Explanation:

Here x = Network range. For example x = 192.168.0.1/24, 172.16.5.1/16 etc

Article Tags :