TCP testing tool under Linux
How to install tcpping on Linux
A common way to measure network latency to a remote host is to use the ping
application. The ping
tool relies on ICMP ECHO request and reply packets to measure the round-trip latency of the remote host. However, in some cases, ICMP traffic may be blocked by a firewall, making the ping
application useless for hosts behind restricted firewalls. In this case, you will need to rely on layer 3 measurement tools that use TCP/UDP packets, as these layer 3 packets are more likely to bypass common firewall rules.

One such layer 3 measurement tool is tcpping
. To measure latency, tcpping
utilizes the so-called semi-open connection technology
, based on TCP three-way handshake. That is, it sends a TCP SYN packet to the remote host via the port number (default is 80). If the remote host is listening on that port, it will respond with a TCP ACK packet. Otherwise, it will respond with a TCP RST packet. Either way, tcpping
can measure the round-trip time (RTT) latency of the remote host by timing outgoing SYN packets and incoming ACK (or RST) packets.
Installation on Linuxtcpping
tcpping
Implemented as a shell script that responds to external tools to perform and report RTT measurements. Therefore, in order to install tcpping
, you first need to install these prerequisites.
Installation dependencies tcptraceroute
To install on Ubuntu or Debiantcptraceroute
:
$ sudo apt-get install tcptraceroute
To install tcptraceroute
on CentOS or RHEL, first set up RepoForge on your system, then run:
$ sudo yum install tcptraceroute
安装依赖 bc
使用的另一个工具tcpping
是GNUbc
,它预装在所有主要的 Linux 发行版上。但是,如果你tcpping
在最小 Linux 运行时环境(例如Docker容器、AWS 最小映像 AMI)中运行,则bc
可能不会预先安装。在这种情况下,你需要bc
自己安装。
在Debian 的 Linux 上安装:
$ sudo apt-get install bc
在 Red Hat 的 Linux 上安装:
$ sudo yum install bc
安装 tcpping
安装这些必备工具后,最后继续tcpping
从官方源下载。
$ wget http://www.vdberg.org/~richard/tcpping $ cp tcpping /usr/bin $ chmod 755 tcpping
使用tcpping
来衡量延迟
要使用 测量网络延迟tcpping
,你可以使用以下格式。
tcpping [-d] [-c] [-r sec] [-x count] ipaddress [端口]
-
-d
: 在每个结果之前打印时间戳。 -
-c
: 使用分列输出以便于解析。 -
-r
:连续探测之间的间隔(以秒为单位)(默认为 1 秒)。 -
-x
: 重复 n 次(默认无限制)。 -
[port]
: 目标端口(默认为 80)。
请注意,你需要 root 权限才能运行,tcpping
因为它需要调用特权tcptraceroute
命令。
对于任何开放 80 端口的目标 Web 服务器,你可以使用以下方法测量其 RTT 延迟tcpping
。
tcpping www.rumenz.com seq 0: tcp response from 42.194.162.109 (42.194.162.109) 33.822 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 1: tcp response from 42.194.162.109 (42.194.162.109) 33.975 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 2: tcp response from 42.194.162.109 (42.194.162.109) 32.010 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 3: tcp response from 42.194.162.109 (42.194.162.109) 32.209 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 4: tcp response from 42.194.162.109 (42.194.162.109) 30.866 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 5: tcp response from 42.194.162.109 (42.194.162.109) 34.866 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 6: tcp response from 42.194.162.109 (42.194.162.109) 32.604 ms traceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets seq 7: tcp response from 42.194.162.109 (42.194.162.109) 30.495 ms
对于任意远程主机,在运行tcpping
. 要检查远程 TCP 端口是否打开,你可以使用nc
如下命令。
$ nc -vn
-t
: 连续 TCPing ,直到使用 Ctrl+C 键停止
tcping -t 1.1.1.1 80
-n 5
: TCPing 5次后停止
tcping -i 5 1.1.1.1 80
-w 0.5
: 设置超时时间为 0.5秒(1秒=1000毫秒),单位 秒
tcping -w 0.5 1.1.1.1 80
-d
:在每行返回信息中加入时间信息
tcping -d 1.1.1.1 80
-s
: 当 TCPing 测试成功后(在超时时间以内返回 TCPing 延迟数据)自动停止 TCPing
tcping -s 1.1.1.1 80
-4
: 优先 IPv4(如果一个域名有 IPv4 和 IPv6 解析,那么走 IPv4)
tcping -s 1.1.1.1 80
-6
:优先 IPv6(如果一个域名有 IPv4 和 IPv6 解析,那么走 IPv6)
tcping -6 www.rumenz.com 80
--file
: TCPing 将逐行循环遍历文件内的 服务器IP/域名 信息(一行一个,支持端口,例如:1.1.1.1 443)
tcping --file rumenz.txt
The above is the detailed content of TCP testing tool under Linux. For more information, please follow other related articles on the PHP Chinese website!

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools