tcp-latency
About
tcp-latency provides an easy way to measure latency using TCP.
Inspired by other similar tools, tcp-latency comes from the need of running network diagnosis/troubleshooting tasks with Python on serverless infrastructure (as many providers don't include ping/ICMP support) but should work too in any other environment with Python>=36.
Features
- Runs as a command-line tool or inside your code as a module.
- Custom parameters for a port, runs, timeout and wait time between runs.
- IPv4 (e.g 52.26.14.11) and domain (e.g google.com) host support.
- Human readable output when running as a command-line tool.
- No external dependencies.
- Small and extensible.
Usage
tcp-latency can be used both as a module and as a standalone script.
Module
>>> from tcp_latency import measure_latency
>>> measure_latency(host='google.com')
[34.57]
>>> measure_latency(host='52.26.14.11', port=80, runs=10, timeout=2.5)
[433.82, 409.21, 409.25, 307.09, 306.64, 409.45, 306.58, 306.93, 409.25, 409.26]
Note: If omitted, measure_latency() arguments use the same defaults that command-line mode.
Command-line
$ tcplatency -h
usage: tcp-latency [-h] [-p [p]] [-t [t]] [-r [r]] [-w [w]] h
Measure latency using TCP.
positional arguments:
host
optional arguments:
-h, --help show this help message and exit
-p [p], --port [p] (default: 443)
-t [t], --timeout [t]
(seconds, float, default: 5)
-r [r], --runs [r] number of latency points (int, default: 5)
-w [w], --wait [w] between each run (seconds, float, default: 1)
$ tcp-latency google.com
tcp-latency google.com
google.com: tcp seq=0 port=443 timeout=5 time=15.16 ms
google.com: tcp seq=1 port=443 timeout=5 time=15.63 ms
google.com: tcp seq=2 port=443 timeout=5 time=14.86 ms
google.com: tcp seq=3 port=443 timeout=5 time=14.76 ms
google.com: tcp seq=4 port=443 timeout=5 time=14.59 ms
--- google.com tcp-latency statistics ---
5 packets transmitted
rtt min/avg/max = 14.76/15.1025/15.63 ms
$ tcp-latency 52.26.14.11 --port 80 --runs 3 --wait 0.5
tcp-latency 52.26.14.11
52.26.14.11: tcp seq=0 port=80 timeout=5 time=230.2 ms
52.26.14.11: tcp seq=1 port=80 timeout=5 time=228.96 ms
52.26.14.11: tcp seq=2 port=80 timeout=5 time=224.51 ms
--- 52.26.14.11 tcp-latency statistics ---
3 packets transmitted
rtt min/avg/max = 228.96/229.57999999999998/230.2 ms
$ tcp-latency google.com -r 1
tcp-latency google.com
google.com: tcp seq=0 port=443 timeout=5 time=34.36 ms
--- google.com tcp-latency statistics ---
1 packets transmitted
Installation
Via pip:
pip install tcp-latency
How to contribute
- Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
- Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
- Write a test which shows that the bug was fixed or that the feature works as expected.
- Send a pull request and bug me until it gets merged and published.
Some things that would be great to have:
- Add transmitted vs received statistics (e.g packet loss)
- Add bytes information (ping-like)
- Add support for machine-readable output (JSON,XML,YAML).
- Add automated releases with TravisCI.
- Improve test suite.
- Improve
How to contributeinformation (pyenv, tox, pre-commit...)
Similar tools
Metadata
Release files for tcp-latency 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tcp-latency-0.0.12.tar.gz | 4.7 kB | Without provenance | Details for tcp-latency-0.0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tcp_latency-0.0.12-py3-none-any.whl | Python 3 | none | any | Details for tcp_latency-0.0.12-py3-none-any.whl |
Total release size: 10.4 kB
Release files / tcp-latency-0.0.12.tar.gz
| Download URL | tcp-latency-0.0.12.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12579351b0852db3a6ddb36f2d8dbd457a21589ee6b1d867fcc12aed8a29097b
|
|
BLAKE2b-256 checksum How to use checksums |
5495dd4032a3562690200074bfc3548c07581205ae5e32c79a63b3f4e47c7c60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.9.0b1+
|
Release files / tcp_latency-0.0.12-py3-none-any.whl
| Download URL | tcp_latency-0.0.12-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abfa0bd094e46f6c64272e2cbc0203900594a068f2a12ba8652f4cca6aec9933
|
|
BLAKE2b-256 checksum How to use checksums |
a7290b84d37e410f7b157edda2b3fef52b181171272264380c9d18221feaa019
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.9.0b1+
|
Security for tcp-latency 0.0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.