Check TCP port reachability on a single IPv4 host using only the Python standard library.
API reference · Changelog · Releases
python -m pip install "pyportscanner>=0.4.0"From a local checkout, run python -m pip install . in the repository root.
Check a local service on port 8000.
from pyportscanner import PortScanner
scanner = PortScanner(target_ports=[8000], timeout=0.5)
print(scanner.scan("127.0.0.1")){8000: 'OPEN'}
The example output assumes a service is listening. The result uses "CLOSE" when a connection fails, including when it times out. To try it with a listener that the example starts for you, run python examples/PortScanExample.py from an installed checkout.
| Input | Ports checked |
|---|---|
target_ports=[8000, 8443] |
The listed ports |
target_ports=3 |
The first three ports in the built-in priority list |
target_ports=None |
All 24 built-in ports |
The legacy import from pyportscanner import pyscanner still works. Version 0.4 replaces the bundled Nmap service database with the built-in list. Pass explicit ports to keep the same targets across versions.
See the contribution guide for local setup, tests, and reporting bugs.
python -m pip install build twine
python -m build
python -m twine check --strict dist/*The build writes a wheel and source distribution to dist/.
Apache-2.0. See the license text.