Skip to main content

Check if a port is open on a host

Project description

philiprehberger-portcheck

Tests PyPI version License

Check if a port is open on a host.

Installation

pip install philiprehberger-portcheck

Usage

from philiprehberger_portcheck import is_open, scan, wait_for

# Single port check
is_open("localhost", 8080)                  # True/False
is_open("192.168.1.1", 22, timeout=2.0)    # True/False

# Scan multiple ports
results = scan("localhost", ports=[80, 443, 8080, 5432])
for port, result in results.items():
    if result.is_open:
        print(f"Port {port}: open ({result.service})")

# Scan common ports
results = scan("localhost", ports="common")

# Wait for a port to become available
wait_for("localhost", 5432, timeout=30)

API

Function / Class Description
is_open(host, port, timeout=2.0) Check if a TCP port is open
scan(host, ports, timeout=1.0, max_workers=50) Scan multiple ports concurrently
wait_for(host, port, timeout=30, interval=1.0) Block until port opens or raise TimeoutError
PortResult Scan result — .port, .is_open, .service
COMMON_PORTS List of well-known port numbers (HTTP, SSH, DB, etc.)

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_portcheck-0.1.6.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_portcheck-0.1.6-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_portcheck-0.1.6.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_portcheck-0.1.6.tar.gz
Algorithm Hash digest
SHA256 f1634ba9352f809a16293dd6c62c83211a70cc7340f0725e849d4a8073bc5c68
MD5 677cd26a293508995fb2deb6d4ec82d0
BLAKE2b-256 638b1d3f367b94a33539baad5595c7c49913c3dcbf1e0a4329839a1ff3f7e6b2

See more details on using hashes here.

File details

Details for the file philiprehberger_portcheck-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_portcheck-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f300c0380e7624a2cbd4137b9597171d2648f9afd7aa3940a313d840b94189c2
MD5 a11c938156a6ed09d79fe59d54e4b0c8
BLAKE2b-256 cec7a7f458a04f7f50ca23ce119980773db5fc7afa5a361c1dd654fa951502b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page