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
Rules first
Only scan localhost, your own devices or a lab (for example a VM). Scanning others' systems without permission can be illegal.
- 2
Single port
socket.create_connection((host, port), timeout=0.5) inside try/except; success = open.
- 3
Many ports
concurrent.futures.ThreadPoolExecutor(max_workers=100) mapping over the port range.
- 4
Service names
socket.getservbyport(port) with a fallback; grab a banner by reading a few bytes where safe.
- 5
CLI
argparse: host, --ports 1-1024, --timeout, --output.
- 6
Report
Write open ports with service and timestamp to JSON.
- 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