Detect Devices on Your Network in 5 Mins: Build a Network Scanner with Python + Scapy

 

Ever wondered "Who's on my WiFi?" Today, we'll build a tool that answers exactly that! Using the powerful Scapy library, we'll create a network scanner that reveals all connected devices. Perfect for home network security monitoring.




Why This Tool is Useful:

  • Detect unknown devices (intruders!).

  • Monitor network activity.

  • Foundation for advanced security tools.


The Code (With Explanation):


# 1. Import libraries
from scapy.all import ARP, Ether, srp

# 2. Define network range (Change 192.168.1.1/24 to yours!)
target_ip = "192.168.1.1/24"

# 3. Create ARP packet
arp = ARP(pdst=target_ip)
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp  # Combine packets

# 4. Send packet & capture responses (timeout=3 sec)
result = srp(packet, timeout=3, verbose=0)[0]

# 5. Print results
print("Discovered Devices:")
for sent, received in result:
    print(f"IP: {received.psrc} - MAC: {received.hwsrc}")

How to Run:

  1. Install library first:

pip install scapy
  1. Save code as network_scanner.py.

  2. Run with:

python network_scanner.py

Security Warning:

⚠️ Use this tool ONLY on your own network or with written permission! Unauthorized scanning is illegal.

What's Next?

  • Enhance it to send alerts when new devices appear (upcoming tutorial!).


You Can Check :

Comments

Popular posts from this blog

🛡️ Automated Security Report Generator (PDF): The Smart Solution for Cybersecurity