3 个方便的命令行网速度测试工具
网速

> 
> 用这三个开源工具检查你的互联网和局域网速度。
> 
> 
> 


![](/data/attachment/album/202002/12/115915kk6hkax1vparkuvk.jpg)


能够验证网络连接速度使您可以控制计算机。 使您可以在命令行中检查互联网和网络速度的三个开源工具是 Speedtest、Fast 和 iPerf。


### Speedtest


[Speedtest](https://github.com/sivel/speedtest-cli) 是一个旧宠。它用 Python 实现，并打包在 Apt 中，也可用 `pip` 安装。你可以将它作为命令行工具或在 Python 脚本中使用。


使用以下命令安装：



```
sudo apt install speedtest-cli
```

或者



```
sudo pip3 install speedtest-cli
```

然后使用命令 `speedtest` 运行它：



```
$ speedtest
Retrieving speedtest.net configuration...
Testing from CenturyLink (65.128.194.58)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by CenturyLink (Cambridge, UK) [20.49 km]: 31.566 ms
Testing download speed................................................................................
Download: 68.62 Mbit/s
Testing upload speed......................................................................................................
Upload: 10.93 Mbit/s
```

它给你提供了互联网上传和下载的网速。它快速而且可脚本调用，因此你可以定期运行它，并将输出保存到文件或数据库中，以记录一段时间内的网络速度。


### Fast


[Fast](https://github.com/sindresorhus/fast-cli) 是 Netflix 提供的服务。它的网址是 [Fast.com](https://fast.com/)，同时它有一个可通过 `npm` 安装的命令行工具：



```
npm install --global fast-cli
```

网站和命令行程序都提供了相同的基本界面：它是一个尽可能简单的速度测试：



```
$ fast

     82 Mbps ↓
```

该命令返回你的网络下载速度。要获取上传速度，请使用 `-u` 标志：



```
$ fast -u

   ⠧ 80 Mbps ↓ / 8.2 Mbps ↑
```

### iPerf


[iPerf](https://iperf.fr/) 测试的是局域网速度（而不是像前两个工具一样测试互联网速度）的好方法。Debian、Raspbian 和 Ubuntu 用户可以使用 apt 安装它：



```
sudo apt install iperf
```

它还可用于 Mac 和 Windows。


安装完成后，你需要在同一网络上的两台计算机上使用它（两台都必须安装 iPerf）。指定其中一台作为服务器。


获取服务端计算机的 IP 地址：



```
ip addr show | grep inet.*brd
```

你的本地 IP 地址（假设为 IPv4 本地网络）以 `192.168` 或 `10` 开头。记下 IP 地址，以便可以在另一台计算机（指定为客户端的计算机）上使用它。


在服务端启动 `iperf`：



```
iperf -s
```

它会等待来自客户端的传入连接。将另一台计算机作为为客户端并运行此命令，将示例中的 IP 替换为服务端计算机的 IP：



```
iperf -c 192.168.1.2
```

![iPerf](/data/attachment/album/202002/12/115954xfcosxwxxfi6hlfo.png "iPerf")


只需几秒钟即可完成测试，然后返回传输大小和计算出的带宽。我使用家用服务器作为服务端，在 PC 和笔记本电脑上进行了一些测试。我最近在房屋周围安装了六类线以太网，因此我的有线连接速度达到 1Gbps，但 WiFi 连接速度却低得多。


![](/data/attachment/album/202002/12/120342d5rz8xzq2uzdarur.jpg)


你可能注意到它记录到 16Gbps。那是我使用服务器进行自我测试，因此它只是在测试写入磁盘的速度。该服务器具有仅 16 Gbps 的硬盘驱动器，但是我的台式机有 46Gbps，另外我的（较新的）笔记本超过了 60Gbps，因为它们都有固态硬盘。


![iPerf](/data/attachment/album/202002/12/120034yyrz58c72ldfu5c5.png "iPerf")


### 总结


通过这些工具来了解你的网络速度是一项非常简单的任务。如果你更喜欢脚本或者在命令行中运行，上面的任何一个都能满足你。如果你要了解点对点的指标，iPerf 能满足你。


你还使用其他哪些工具来衡量家庭网络？在评论中分享你的评论。


本文最初发表在 Ben Nuttall 的 [Tooling blog](https://tooling.bennuttall.com/command-line-speedtest-tools/) 上，并获准在此使用。




---


via: <https://opensource.com/article/20/1/internet-speed-tests>


作者：[Ben Nuttall](https://opensource.com/users/bennuttall) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Being able to validate your network connection speed puts you in control of your computer. Three open source tools that enable you to check your internet and network speeds at the command line are Speedtest, Fast, and iPerf.

## Speedtest

[Speedtest](https://github.com/sivel/speedtest-cli) is an old favorite. It's implemented in Python, packaged in Apt, and also available with pip. You can use it as a command-line tool or within a Python script.

Install it with:

`sudo apt install speedtest-cli`


or

`sudo pip3 install speedtest-cli`


Then run it with the command **speedtest**:

```
$ speedtest
Retrieving speedtest.net configuration...
Testing from CenturyLink (65.128.194.58)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by CenturyLink (Cambridge, UK) [20.49 km]: 31.566 ms
Testing download speed................................................................................
Download: 68.62 Mbit/s
Testing upload speed......................................................................................................
Upload: 10.93 Mbit/s
```


This gives you your download and upload Internet speeds. It's fast and scriptable, so you can run it regularly and save the output to a file or database for a record of your network speed over time.

## Fast

[Fast](https://github.com/sindresorhus/fast-cli) is a service provided by Netflix. Its web interface is located at [Fast.com](https://fast.com/), and it has a command-line interface available through npm:

`npm install --global fast-cli`


Both the website and command-line utility provide the same basic interface: it's a simple-as-possible speed test:

```
$ fast
82 Mbps ↓
```


The command returns your Internet download speed. To get your upload speed, use the **-u** flag:

```
$ fast -u
⠧ 80 Mbps ↓ / 8.2 Mbps ↑
```


## iPerf

[iPerf](https://iperf.fr/) is a great way to test your LAN speed (rather than your Internet speed, as the two previous tools do). Debian, Raspbian, and Ubuntu users can install it with **apt**:

`sudo apt install iperf`


It's also available for Mac and Windows.

Once it's installed, you need two machines on the same network to use it (both must have iPerf installed). Designate one as the server.

Obtain the IP address of the server machine:

`ip addr show | grep inet.*brd`


Your local IP address (assuming an IPv4 local network) starts with either **192.168** or **10**. Take note of the IP address so you can use it on the other machine (the one designated as the client).

Start **iperf** on the server:

`iperf -s`


This waits for incoming connections from clients. Designate another machine as a client and run this command, substituting the IP address of your server machine for the sample one here:

`iperf -c 192.168.1.2`



![iPerf iPerf](https://opensource.com/sites/default/files/uploads/iperf.png)

It only takes a few seconds to do a test, and it returns the transfer size and calculated bandwidth. I ran a few tests from my PC and my laptop, using my home server as the server machine. I recently put in Cat6 Ethernet around my house, so I get up to 1Gbps speeds from my wired connections but much lower speeds on WiFi connections.

![iPerf iPerf](https://opensource.com/sites/default/files/uploads/iperf2.png)

You may notice where it recorded 16Gbps. That was me using the server to test itself, so it's just testing how fast it can write to its own disk. The server has hard disk drives, which are only 16Gbps, but my desktop PC gets 46Gbps, and my (newer) laptop gets over 60Gbps, as they have solid-state drives.

![iPerf iPerf](https://opensource.com/sites/default/files/uploads/iperf3.png)

## Wrapping up

Knowing the speed of your network is a rather straightforward task with these tools. If you prefer to script or run these from the command line for the fun of it, any of the above projects will get you there. If you're after specific point-to-point metrics, iPerf is your go-to.

What other tools do you use to measure the network at home? Share in the comments.

*This article was originally published on Ben Nuttall's Tooling blog and is used here with permission.*

## 7 Comments