Home » Tutorials » How to Make a Hidden Networks Scanner in Python

How to Make a Hidden Networks Scanner in Python

In our last discussion, we explored building a Wi-Fi network scanner and security analyzer, focusing on visible networks and their security features. However, one crucial aspect we haven’t yet tackled is the ability to detect and analyze hidden Wi-Fi networks.

In today’s tutorial, we’re going to create a Hidden Wi-Fi Network Scanner using Scapy in Python. You’ll learn how to scan hidden networks and analyze their security.

Let’s get started!

Table of Contents

Disclaimer

Please note: before we proceed with this code,  it is imperative for me to warn you not to use this code illegally or without consent since it is for educational purposes only.

Necessary Libraries

Make sure to install the Scapy library via the terminal or your command prompt for the code to function properly:

$ pip install scapy

Imports

We start by importing subprocess so we can use external commands in Python, and then we import everything from scapy since this library can analyze and manipulate network packets.

import subprocess
from scapy.all import *

analyze_hidden_network_security Function

This function’s job is to analyze the security of the hidden Wi-Fi network and test the strength of the encryption used by it (WPA, WEP, TKIP), If the encryption is strong, it prints “Strong“; if it’s weak, it prints “Advice“.

def analyze_hidden_network_security(ssid, encryption_type):
   """Analyze the security of a hidden Wi-Fi network."""
   print(f"Analyzing security for hidden network: {ssid}")


   if encryption_type.upper() in ['WEP', 'WPA', 'TKIP']:
       print("Warning: Weak encryption type detected.")
       print("Advice: Consider upgrading to WPA2 or WPA3 for stronger security.")
   else:
       print("Security: Strong")
       print("Advice: Keep your Wi-Fi password strong and secure, and regularly update your router firmware.")

scan_hidden_networks Function

As the name of the function suggests, it looks for hidden networks by listening to Wi-Fi signals, if it detects a signal without the SSID (network name) being broadcast. It defines it as a hidden network, once this happens this function will call the analyze_hidden_network_security() function to analyze this hidden network while printing that “it is scanning for hidden networks“. If an error occurs during the process, an error message will be displayed.

def scan_hidden_networks(interface):
   hidden_networks = set()


   def handle_probe_response(packet):
       if packet.haslayer(Dot11ProbeResp) and packet.info:
           ssid = packet.info.decode(errors="ignore")
           if ssid not in hidden_networks:
               hidden_networks.add(ssid)
               encryption_type = 'Unknown'  # Encryption type determination needs a different approach
               analyze_hidden_network_security(ssid, encryption_type)


   try:
       print("Scanning for hidden networks. Please wait...")
       sniff(iface=interface, prn=handle_probe_response, timeout=20)
   except Exception as e:
       print(f"Error scanning for hidden networks: {e}")


   return hidden_networks

Main Function

def main():
   interface = input("Enter the wireless interface name (e.g., Wi-Fi): ")
   hidden_networks = scan_hidden_networks(interface)
   print(f"\nDiscovered {len(hidden_networks)} hidden networks:")
   for ssid in hidden_networks:
       print(ssid)

What this function does is ask the user for the name of their wireless interface, which in my case is ‘Wi-Fi’. Then, it calls the previous function to scan for hidden networks. If any are found, it prints their numbers along with their names. If nothing is found, it prints “0“.

Main Block

Lastly, this part of the code ensures that the main () function works only if this script is run directly and not imported as a module.

if __name__ == "__main__":
   main()

Example

Full Code

import subprocess
from scapy.all import *


def analyze_hidden_network_security(ssid, encryption_type):
   """Analyze the security of a hidden Wi-Fi network."""
   print(f"Analyzing security for hidden network: {ssid}")


   if encryption_type.upper() in ['WEP', 'WPA', 'TKIP']:
       print("Warning: Weak encryption type detected.")
       print("Advice: Consider upgrading to WPA2 or WPA3 for stronger security.")
   else:
       print("Security: Strong")
       print("Advice: Keep your Wi-Fi password strong and secure, and regularly update your router firmware.")


def scan_hidden_networks(interface):
   hidden_networks = set()


   def handle_probe_response(packet):
       if packet.haslayer(Dot11ProbeResp) and packet.info:
           ssid = packet.info.decode(errors="ignore")
           if ssid not in hidden_networks:
               hidden_networks.add(ssid)
               encryption_type = 'Unknown'  # Encryption type determination needs a different approach
               analyze_hidden_network_security(ssid, encryption_type)


   try:
       print("Scanning for hidden networks. Please wait...")
       sniff(iface=interface, prn=handle_probe_response, timeout=20)
   except Exception as e:
       print(f"Error scanning for hidden networks: {e}")


   return hidden_networks


def main():
   interface = input("Enter the wireless interface name (e.g., Wi-Fi): ")
   hidden_networks = scan_hidden_networks(interface)
   print(f"\nDiscovered {len(hidden_networks)} hidden networks:")
   for ssid in hidden_networks:
       print(ssid)


if __name__ == "__main__":
   main()

Happy Coding!

Subscribe for Top Free Python Tutorials!

Receive the best directly.  Elevate Your Coding Journey!

Leave a Comment

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

Scroll to Top
×