🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

Network port scanner

Scan your own machine or lab network for open ports and services, to understand how attack surfaces are mapped.

Beginner⏱ 4–6 hoursđŸĒœ 7 stepsPythonsocketthreading

What you'll learn

  • ◆TCP connections and ports
  • ◆Concurrency with threads
  • ◆Why permission matters in security work

What you'll build

  • ✓Scan a host and port range
  • ✓Fast multi-threaded scanning
  • ✓Service names for common ports
  • ✓Report saved as JSON

Step-by-step guide

  1. 1

    Rules first

    Only scan localhost, your own devices or a lab (for example a VM). Scanning others' systems without permission can be illegal.

  2. 2

    Single port

    socket.create_connection((host, port), timeout=0.5) inside try/except; success = open.

  3. 3

    Many ports

    concurrent.futures.ThreadPoolExecutor(max_workers=100) mapping over the port range.

  4. 4

    Service names

    socket.getservbyport(port) with a fallback; grab a banner by reading a few bytes where safe.

  5. 5

    CLI

    argparse: host, --ports 1-1024, --timeout, --output.

  6. 6

    Report

    Write open ports with service and timestamp to JSON.

  7. 7

    Compare

    Run nmap on the same lab host and compare results; explain the difference between connect and SYN scans.

🚀 Make it stand out

  • +UDP scanning basics
  • +Detect OS from TTL (lab only)
  • +Simple web dashboard