Skip to main content

A tiny, dependency-free Python library for TCP and UDP connectivity checks with IPv4/IPv6, DNS, detailed error diagnostics, and optional protocol probing.

Project description

pyminitcp

PyPI version Build status Python versions License

A tiny, dependency-free Python library for TCP and UDP connectivity checks with IPv4/IPv6, DNS, detailed error diagnostics, and optional protocol probing.

  • No dependencies
  • IPv4 / IPv6 support
  • DNS + connect timing
  • UDP payload support
  • Detailed error info (phase, errno)
  • Optional banner / protocol probing

Installation

pip install pyminitcp

Usage (CLI)

TCP check

pyminitcp example.com 443

UDP check

pyminitcp example.com 53 --udp

Banner / protocol probe

Read data after connect:

pyminitcp example.com 22 --banner

Require banner (fail if not received):

pyminitcp example.com 22 --banner --require-banner

Send data before reading response

HTTP

pyminitcp example.com 80 \
  --banner --require-banner \
  --send-data $'HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n'

Redis

pyminitcp 127.0.0.1 6379 \
  --banner --require-banner \
  --send-data $'PING\r\n'

Hex payload

pyminitcp host 12345 --banner --send-hex 50494e470d0a

Typical probes

Service Port Options Request data Expected banner / response Notes
SSH 22 --banner none SSH-2.0-... Usually sends banner immediately after connect
SMTP 25 --banner --require-banner none 220 ... Greeting usually arrives without request
SMTPS 465 --banner none often none Usually TLS first, plain banner is not expected
FTP 21 --banner --require-banner none 220 ... Classic FTP greeting
POP3 110 --banner --require-banner none +OK ... Usually sends greeting immediately
IMAP 143 --banner --require-banner none * OK ... Usually sends greeting immediately
HTTP 80 --banner --require-banner --send-data $'HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n' HEAD / HTTP/1.0 HTTP/1.0 200 OK or similar HTTP does not send banner until request
HTTPS 443 not suitable for plain banner probe none none Needs TLS probe, not plain TCP banner read
Redis 6379 --banner --require-banner --send-data $'PING\r\n' PING\r\n +PONG Good lightweight protocol probe
Memcached 11211 --banner --require-banner --send-data $'version\r\n' version\r\n VERSION ... Simple text command
MySQL 3306 --banner none handshake packet Response is binary, banner may be unreadable text
PostgreSQL 5432 --banner or custom request none usually none Better with a protocol-specific probe
DNS over UDP 53 --udp --hex-payload <dns_query_hex> DNS query binary response Best used with a real DNS query payload
NTP over UDP 123 --udp --hex-payload <ntp_query_hex> NTP request binary response Response is binary
Custom TCP service custom --banner or --banner --send-data ... service-specific service-specific Useful for app protocols with text replies

CLI options

--udp               Use UDP instead of TCP
--timeout           Timeout (seconds)

--banner            Read response after connect
--require-banner    Fail if banner is not received
--read-bytes        Bytes to read (default: 1024)

--send-data         Send text before reading response
--send-hex          Send hex payload before reading response

--json              Output JSON

Python usage

TCP

from pyminitcp import tcp_check

result = tcp_check("example.com", 443)
print(result)

TCP + banner

result = tcp_check(
    "example.com",
    80,
    banner=True,
    require_banner=True,
    request_data=b"HEAD / HTTP/1.0\r\nHost: example.com\r\n\r\n"
)

Result fields

{
  "status": 1,
  "resp_time": 0.012,
  "error": "",
  "family": "AF_INET",
  "sockaddr": ["142.250.74.238", 443],
  "namelookup_time": 0.001,
  "connect_time": 0.010,
  "phase": null,
  "errno_code": null,
  "errno_name": null,
  "os_error": null,
  "banner": "HTTP/1.1 200 OK"
}

Error model

Errors include detailed diagnostics:

Field Description
phase resolve / connect / send / recv
errno_code OS error code
errno_name e.g. ECONNREFUSED
os_error human-readable OS message

Example errors

Connection refused

{
  "phase": "connect",
  "errno_name": "ECONNREFUSED"
}

DNS failure

{
  "phase": "resolve"
}

Banner timeout

{
  "phase": "recv",
  "error": "Timed out waiting for banner"
}

Notes

  • TCP check = L4 connectivity
  • Banner probe = L7-style check
  • UDP check expects response (request/response model)
  • Some UDP services do not reply — use carefully

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

pyminitcp-2.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

pyminitcp-2.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file pyminitcp-2.1.0.tar.gz.

File metadata

  • Download URL: pyminitcp-2.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyminitcp-2.1.0.tar.gz
Algorithm Hash digest
SHA256 51f3fcc29cf5e9a095895cb1fcd3a52bef7d833a0ddcef497b98839b58e7cd0d
MD5 671b23aae65b28344008e83a6aeaa797
BLAKE2b-256 000699732cf734825f27a530ae02e03687e452b5c76cab05e7ce1bee14a0e219

See more details on using hashes here.

File details

Details for the file pyminitcp-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyminitcp-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyminitcp-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87243e59dcdd8fb90d20d5552486a1b6dae6f2b4dce9ea119414e91021bd2165
MD5 b4dee1b845c22e3b5e023897432e19b9
BLAKE2b-256 d81c62ea24fc0b9f5e11baafec70a8492ca91d024baab15805f9e385fd4b5ba8

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