How to Find Every Device on Your Wi-Fi Network Using Python (LAN Scanner)

This tutorial is perfect for:

By the end of this tutorial you'll know how to:

Why This Project Is Cool?

Ever wonder what devices are connected to your Wi-Fi? This project scans your local network and checks which IP addresses respond to a ping request.

A network scanner can help you locate:

In this tutorial we'll build a simple Python network scanner that checks for active devices on your local network.

By the end, you'll have a practical networking tool and a better understanding of how local networks operate.

What Is a LAN Scanner?

A LAN (Local Area Network) scanner checks IP addresses on your network to determine which devices are currently online.

Before We Begin

This project is intended for educational purposes and should only be used on networks you own or have permission to test.

__________

__________

Step 1: Import Required Modules

Code

import subprocess import platform

subprocess Allows Python to execute operating system commands.

platform Detects whether you're running Windows, macOS, or Linux.

Step 2: Create a Ping Function

Code

def ping(ip): param = "-n" if platform.system().lower() == "windows" else "-c" command = ["ping", param, "1", ip] result = subprocess.run( command, capture_output=True, text=True ) return result.returncode == 0

This function: Sends a ping request. Waits for a response. Then returns: "True" if a device responds.

otherwise it returns: "False"

__________

__________

Step 3: Scan Your Wi-Fi Network

Code

for i in range(1, 255): ip = f"192.168.1.{i}" if ping(ip): print(f"Device Found: {ip}")

Python checks every address between:

192.168.1.1

And

192.168.1.254

Step 4: run the script

Final Code

import subprocess import platform def ping(ip): param = "-n" if platform.system().lower() == "windows" else "-c" command = ["ping", param, "1", ip] result = subprocess.run( command, capture_output=True, text=True ) return result.returncode == 0 print("Scanning Wi-Fi Network...") print() for i in range(1, 255): ip = f"192.168.1.{i}" if ping(ip): print(f"Device Found: {ip}") print() print("Scan Complete")

Example Output

Scanning Wi-Fi Network... Device Found: 192.168.1.1 Device Found: 192.168.1.15 Device Found: 192.168.1.28 Device Found: 192.168.1.50 Scan Complete

Challenge Mode ⭐