philiprehberger-portcheck
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)
Service lookup
from philiprehberger_portcheck import SERVICES, service_name
service_name(443) # "https"
service_name(22) # "ssh"
service_name(99999) # "" (unknown port)
# Read directly from the well-known port map
SERVICES[5432] # "postgresql"
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 |
service_name(port) |
Look up the service name for a port (falls back to socket.getservbyport) |
PortResult |
Scan result — .port, .is_open, .service |
SERVICES |
Read-only mapping of well-known port numbers to service names |
COMMON_PORTS |
List of well-known port numbers (HTTP, SSH, DB, etc.) |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Release files for philiprehberger-portcheck 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| philiprehberger_portcheck-0.2.0.tar.gz | 173.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| philiprehberger_portcheck-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 178.3 kB
Release files / philiprehberger_portcheck-0.2.0.tar.gz
| Download URL | philiprehberger_portcheck-0.2.0.tar.gz |
|---|---|
| Size | 173.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ecea7d137574ea6435ce18a5f272ea215d0d0bf6f0d0bf14514062a872dbe01
|
|
BLAKE2b-256 checksum How to use checksums |
9b24f0541a316143782981e9204d3ff0ad46629fbc22eb3625070a3ce39eac76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_portcheck-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_portcheck-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2df4de90d4d9f69517ce5abde5467724fb6cc307fd5e7e38ac0730ad81784547
|
|
BLAKE2b-256 checksum How to use checksums |
d0a103e7b7081ef7cf7383c207e28e6cd3923bf2eb61966e9ede07701010e4f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|