使用TCP测量延迟。
tcp-latenc的Python项目详细描述
TCP延迟
关于
tcp-latency
提供了一种使用tcp测量延迟的简单方法。
受其他similar tools的启发,tcp-latency
来自于在无服务器基础设施上使用python运行网络诊断/故障排除任务的需要(因为许多提供程序不包括ping/icmp支持),但是在python>;=36的任何其他环境中也应该可以使用。
功能
- 作为命令行工具运行,或作为模块在代码中运行。
- 端口、运行、超时和运行之间等待时间的自定义参数。
- IPv4(例如52.26.14.11)和域(例如google.com)主机支持。
- 作为命令行工具运行时的可读输出。
- 小而可扩展。
用法
tcp-latency
既可以用作模块,也可以用作独立脚本。
模块
>>> 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]
注意:如果省略,measure_latency()
参数使用与命令行模式相同的默认值。
命令行
$ 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: 0)
$ tcplatency google.com
tcp-latency google.com
google.com: tcp seq=0 port=443 timeout=5 time=32.91 ms
google.com: tcp seq=1 port=443 timeout=5 time=14.1 ms
google.com: tcp seq=2 port=443 timeout=5 time=16.26 ms
google.com: tcp seq=3 port=443 timeout=5 time=16.35 ms
google.com: tcp seq=4 port=443 timeout=5 time=15.63 ms
--- google.com tcp-latency statistics ---
5 packets transmitted
$ tcplatency 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=269.45 ms
52.26.14.11: tcp seq=1 port=80 timeout=5 time=409.2 ms
52.26.14.11: tcp seq=2 port=80 timeout=5 time=409.14 ms
--- 52.26.14.11 tcp-latency statistics ---
3 packets transmitted
$ 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
安装
通过PIP:
pip install tcp-latency
如何贡献
- 检查打开的问题或打开一个新的问题,开始围绕功能想法或错误的讨论。
- 在github上分叉the repository,开始对主分支(或其分支)进行更改。
- 编写一个测试,显示错误已修复或功能按预期工作。
- 发送一个pull request和错误me,直到它被合并并发布。
有些东西会很棒:
- 在human_output statistics的末尾添加(类似ping)。
- 添加文档(sphinx?).
- 添加IPv6支持。
- 添加对机器可读输出(json?XML格式?).
- 使用travisci添加自动发布。
- 添加codecov。
- 改进human_输出中的格式,使其更像ping。
- 改进测试套件。
- 改进
How to contribute
信息(pyenv、tox、pre-commit…)