A minimal, threaded TCP port scanner with host resolution and service detection.
- Resolve hostname to IP and reverse DNS lookup
- Validate IPv4/IPv6 addresses
- Threaded TCP connect scans: open/closed/filtered
- Basic service detection via well-known ports and getservbyport
- Python 3.8+
- No external dependencies
- Tests use pytest
# optional: create & activate a virtual environment
python -m venv .venv
# Windows PowerShell
. .venv/Scripts/Activate.ps1
# or Git Bash
source .venv/Scripts/activate
# install test dependency (optional if you only run the script)
pip install -U pytest# Run a simple scan (defaults inside scanner.py)
python scanner.pyBy default, it resolves and scans the first 1024 TCP ports of scanme.nmap.org using 50 threads. To change the target, edit the target variable in scanner.py.
pytest -qA pytest.ini is included so the project root is on the import path.
port-scanner/
├─ scanner.py # main scanner module & CLI entry
├─ pytest.ini # ensures project root on PYTHONPATH for tests
├─ tests/ # unit tests
└─ README.md # this file
- Scan only hosts you have permission to test.
- Adjust timeouts/threads carefully to avoid false "filtered" or network overload.