生成具有指定吞吐量的流量

Nak*_*ule 8 networking

为了测试我的网络,我想在两台主机之间发送 x MB/s。我知道这ping可用于发送大量数据,但我需要一个可以设置带宽的解决方案(它不必非常精确)。

$ sendTrafic --throughput 10M 10.0.0.1
Run Code Online (Sandbox Code Playgroud)

知道我该怎么做吗?我想过一个scappy每秒运行x 次的脚本,但应该有更好的东西。


编辑:我使用了以下解决方案:

# On receiving node:
iperf -s -u

# On sending node:
iperf -c <ip> -u -b 10m -t 30
Run Code Online (Sandbox Code Playgroud)

它将第一台主机配置为 UDP 服务器,将第二台主机配置为 UDP 客户端,以 10Mb/s 的速度发送 30 秒。

感谢大家的帮助。

Kiw*_*iwy 13

如果您不想安装iperf(这不是我过去使用的最可靠的工具,恕我直言),您可以使用pvandnetcat
您首先需要安装pvand netcat(它在大多数发行版中可用)。
在接收站点上,您将需要一个可访问端口上的侦听套接字:

#if you want the output you can remove the redirection or redirect it to a different file.
#if you want to listen to a TCP port below 1024 you will need to use root
nc -l 4444 > /dev/null
Run Code Online (Sandbox Code Playgroud)

在发送机器上,您将使用此命令:

dd if=/dev/urandom bs=1000 count=1000 | pv -L 10M | nc <ip> 4444
Run Code Online (Sandbox Code Playgroud)

dd if=/dev/urandom bs=1000 count=1000将发送 1000 个随机字符(1000 字节)的块 1000 次: 1000B * 1000 = 1MB 。您可以调整计数以增加发送的数据量。
pv -L 10M: 将写入速率限制为 10 mebibytes/s (*1024)。
netcat <ip> 4444将数据发送到端口 TCP 4444 上的 IP。

您可以使用以下方法发送更多数据甚至真实文件:

cat /some/files| pv -L 1M | nc <ip> 4444
Run Code Online (Sandbox Code Playgroud)

另一方面:

 nc -l 4444 > /some/destinationfiles
Run Code Online (Sandbox Code Playgroud)