As a Linux developer, have you ever spent a lot of time learning network programming and encountered countless problems and challenges? If that's the case, then you've come to the right place! This article will introduce the basic knowledge and common applications of network programming under Linux to help you understand this wonderful world more deeply.
fast
fast is a service provided by Netflix, which can be used not only through the command line, but also directly on the web: fast.com.
We can install this tool through the following command:
$ npm install --global fast-cli
Whether it is the web page or the command line, it provides the most basic network download speed test. The simplest way to use it from the command line is as follows:
$ fast 93 Mbps ↓
As can be seen from the above results, if you use the fast command directly, only the network download speed will be returned. If you also want to get the upload speed of the network, you need to use the -u option.
$ fast -u ⠧ 81 Mbps ↓ / 8.3 Mbps ↑
speedtest
speedtest is a more well-known tool. It is written in Python and can be installed using the apt or pip command. You can use it from the command line or import it directly into your Python project.
Installation method:
$ sudo apt install speedtest-cli $ sudo pip3 install speedtest-cli
When using it, you can directly run the speedtest command:
$ speedtest Retrieving speedtest.net configuration... Testing from Tencent cloud computing (140.143.139.14)... Retrieving speedtest.net server list... Selecting best server based on ping... Hosted by Henan CMCC 5G (Zhengzhou) [9.69 km]: 28.288 ms Testing download speed................................................................................ Download: 56.20 Mbit/s
Testing upload speed…………………………………………………………………………………………
Upload: 1.03 Mbit/s
It can be seen from the running results that the speedtest command will directly provide the upload/download rate, and the testing process is also very fast. You can write a script to call this command, and then perform network tests regularly and save the results in a file or database, so that you can track the status of your network in real time.
iPerf
iperf is a network performance testing tool that can test TCP and UDP bandwidth quality, can measure the maximum TCP bandwidth, has a variety of parameters and UDP characteristics, and can report bandwidth, delay jitter and packet loss. Using this feature of iperf, you can test the performance of some network devices such as routers, firewalls, switches, etc.
Debian-based distributions can use the following command to install iPerf:
$ sudo apt install iperf
This tool is not only available on Linux systems, but also on Mac and Windows systems.
If you want to test network bandwidth, you need two computers. The two computers need to be on the same network, one as a server and the other as a client, and iPerf must be installed on both.
You can obtain the IP address of the server through the following command:
$ ip addr show | grep inet.*brd inet 192.168.242.128/24 brd 192.168.242.255 scope global dynamic noprefixroute ens33
We know that in the LAN, our ipv4 address generally starts with 192.168. After running the above command, we need to write down the address of the server machine, which will be used later.
After that, we start the iperf tool on the server machine:
$ iperf -s
Then, we can wait for the client to access. The client can use the following command to connect to the server:
$ iperf -c 192.168.242.128
After a few seconds of testing, it will return the network transmission rate and bandwidth.
Through this article, we have learned the basic knowledge of network programming under Linux, and we have also learned some common techniques and methods in practical applications. Network programming is a very important and widely used field in Linux systems. Mastering it is very helpful for our career development and technical improvement. I hope this article can inspire and help you, allowing you to explore and apply network programming technology under Linux more deeply.
The above is the detailed content of Let's explore the wonderful world of network programming under Linux!. For more information, please follow other related articles on the PHP Chinese website!