请教一个打流的脚本

sh/bash/dash/ksh/zsh等Shell脚本
回复
sixtome
帖子: 3
注册时间: 2020-12-19 17:26

请教一个打流的脚本

#1

帖子 sixtome » 2022-02-16 14:07

#!/bin/bash

FM1_MAC1=`ifconfig fm1-mac1 | awk '/ether/{print $2}'`
FM1_MAC2=`ifconfig fm1-mac2 | awk '/ether/{print $2}'`
FM1_MAC3=`ifconfig fm1-mac3 | awk '/ether/{print $2}'`
FM1_MAC4=`ifconfig fm1-mac4 | awk '/ether/{print $2}'`
FM1_MAC5=`ifconfig fm1-mac5 | awk '/ether/{print $2}'`
FM1_MAC6=`ifconfig fm1-mac6 | awk '/ether/{print $2}'`
FM1_MAC9=`ifconfig fm1-mac9 | awk '/ether/{print $2}'`
FM1_MAC10=`ifconfig fm1-mac10 | awk '/ether/{print $2}'`

ifconfig fm1-mac1 192.168.1.1 netmask 255.255.255.0
ifconfig fm1-mac2 192.168.1.2 netmask 255.255.255.0
ifconfig fm1-mac3 192.168.1.3 netmask 255.255.255.0
ifconfig fm1-mac4 192.168.1.4 netmask 255.255.255.0
ifconfig fm1-mac5 192.168.1.5 netmask 255.255.255.0
ifconfig fm1-mac6 192.168.1.6 netmask 255.255.255.0
ifconfig fm1-mac9 192.168.1.9 netmask 255.255.255.0
ifconfig fm1-mac10 192.168.1.10 netmask 255.255.255.0

(route add 192.168.1.11 dev fm1-mac1 &)
(route add 192.168.1.22 dev fm1-mac2 &)
(route add 192.168.1.33 dev fm1-mac3 &)
(route add 192.168.1.44 dev fm1-mac4 &)
(route add 192.168.1.55 dev fm1-mac5 &)
(route add 192.168.1.66 dev fm1-mac6 &)
(route add 192.168.1.99 dev fm1-mac9 &)
(route add 192.168.1.101 dev fm1-mac10 &)

arp -i fm1-mac1 -s 192.168.1.11 $FM1_MAC10
arp -i fm1-mac10 -s 192.168.1.101 $FM1_MAC1
arp -i fm1-mac2 -s 192.168.1.22 $FM1_MAC9
arp -i fm1-mac9 -s 192.168.1.99 $FM1_MAC2
arp -i fm1-mac3 -s 192.168.1.33 $FM1_MAC4
arp -i fm1-mac4 -s 192.168.1.44 $FM1_MAC3
arp -i fm1-mac5 -s 192.168.1.55 $FM1_MAC6
arp -i fm1-mac6 -s 192.168.1.66 $FM1_MAC5

iptables -t nat -F

iptables -t nat -A POSTROUTING -s 192.168.1.1 -d 192.168.1.11 -j SNAT --to-source 192.168.1.101
iptables -t nat -A PREROUTING -s 192.168.1.101 -d 192.168.1.11 -j DNAT --to-destination 192.168.1.10

iptables -t nat -A POSTROUTING -s 192.168.1.10 -d 192.168.1.101 -j SNAT --to-source 192.168.1.11
iptables -t nat -A PREROUTING -s 192.168.1.11 -d 192.168.1.101 -j DNAT --to-destination 192.168.1.1

iptables -t nat -A POSTROUTING -s 192.168.1.2 -d 192.168.1.22 -j SNAT --to-source 192.168.1.99
iptables -t nat -A PREROUTING -s 192.168.1.99 -d 192.168.1.22 -j DNAT --to-destination 192.168.1.9

iptables -t nat -A POSTROUTING -s 192.168.1.9 -d 192.168.1.99 -j SNAT --to-source 192.168.1.22
iptables -t nat -A PREROUTING -s 192.168.1.22 -d 192.168.1.99 -j DNAT --to-destination 192.168.1.2

iptables -t nat -A POSTROUTING -s 192.168.1.3 -d 192.168.1.33 -j SNAT --to-source 192.168.1.44
iptables -t nat -A PREROUTING -s 192.168.1.44 -d 192.168.1.33 -j DNAT --to-destination 192.168.1.4

iptables -t nat -A POSTROUTING -s 192.168.1.4 -d 192.168.1.44 -j SNAT --to-source 192.168.1.33
iptables -t nat -A PREROUTING -s 192.168.1.33 -d 192.168.1.44 -j DNAT --to-destination 192.168.1.3

iptables -t nat -A POSTROUTING -s 192.168.1.5 -d 192.168.1.55 -j SNAT --to-source 192.168.1.66
iptables -t nat -A PREROUTING -s 192.168.1.66 -d 192.168.1.55 -j DNAT --to-destination 192.168.1.6

iptables -t nat -A POSTROUTING -s 192.168.1.6 -d 192.168.1.66 -j SNAT --to-source 192.168.1.55
iptables -t nat -A PREROUTING -s 192.168.1.55 -d 192.168.1.66 -j DNAT --to-destination 192.168.1.5


对后面的arp 和iptables脚本不是很理解 ,那位大侠可以给详细解释下;
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: 请教一个打流的脚本

#2

帖子 astolia » 2022-02-17 2:16

从前面的ifconfig和route来看,网络拓扑结构大概是这样的(单以fm1-mac1和fm1-mac10为例)

代码: 全选

192.168.1.11 --- 192.168.1.1(fm1-mac1)--- 本机 --- 192.168.1.10(fm1-mac10)--- 192.168.1.101
arp乱设置一通,我也不知道是为了啥。
iptables设置的nat也很奇怪,感觉像是想让192.168.1.11和192.168.1.101能相互通信,但又没写对
sixtome
帖子: 3
注册时间: 2020-12-19 17:26

Re: 请教一个打流的脚本

#3

帖子 sixtome » 2022-02-17 8:58

补充以下,这个脚本的用途,这个装置共8个网口,由于是嵌入式系统,不能在设置8个网口在同一个网段,要设置ip转换,实验过程中使用网线两两对接,循环打流,看速度,连接是否异常。
sixtome
帖子: 3
注册时间: 2020-12-19 17:26

Re: 请教一个打流的脚本

#4

帖子 sixtome » 2022-02-17 11:04

运行脚本结果如下:
[2022-2-16 15:41:05] Server listening on 5201
[2022-2-16 15:41:05] -----------------------------------------------------------
[2022-2-16 15:41:06] 11: Connecting to host 192.168.1.11, port 5201
[2022-2-16 15:41:06] Accepted connection from 192.168.1.101, port 53602
[2022-2-16 15:41:06] 11: [ 4] local 192.168.1.1 port 53604 connected to 192.168.1.11 port 5201
[2022-2-16 15:41:06] [ 5] local 192.168.1.10 port 5201 connected to 192.168.1.101 port 53604
[2022-2-16 15:41:07] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:07] [ 5] 0.00-1.00 sec 109 MBytes 913 Mbits/sec
[2022-2-16 15:41:07] 11: [ ID] Interval Transfer Bandwidth Retr Cwnd
[2022-2-16 15:41:07] 11: [ 4] 0.00-1.00 sec 114 MBytes 956 Mbits/sec 0 294 KBytes
[2022-2-16 15:41:08] [ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:08] 11: [ 4] 1.00-2.00 sec 112 MBytes 943 Mbits/sec 0 310 KBytes
[2022-2-16 15:41:09] [ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:09] 11: [ 4] 2.00-3.00 sec 112 MBytes 942 Mbits/sec 0 324 KBytes
[2022-2-16 15:41:10] [ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:10] 11: [ 4] 3.00-4.00 sec 112 MBytes 942 Mbits/sec 0 344 KBytes
[2022-2-16 15:41:11] [ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:11] 11: [ 4] 4.00-5.00 sec 112 MBytes 943 Mbits/sec 0 361 KBytes
[2022-2-16 15:41:12] [ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:12] 11: [ 4] 5.00-6.00 sec 112 MBytes 942 Mbits/sec 0 380 KBytes
[2022-2-16 15:41:13] [ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:13] 11: [ 4] 6.00-7.00 sec 112 MBytes 942 Mbits/sec 0 380 KBytes
[2022-2-16 15:41:14] [ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:14] 11: [ 4] 7.00-8.00 sec 112 MBytes 941 Mbits/sec 0 380 KBytes
[2022-2-16 15:41:15] [ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:15] 11: [ 4] 8.00-9.00 sec 113 MBytes 945 Mbits/sec 0 465 KBytes
[2022-2-16 15:41:16] [ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:16] [ 5] 10.00-10.03 sec 3.43 MBytes 939 Mbits/sec
[2022-2-16 15:41:16] - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:16] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:16] [ 5] 0.00-10.03 sec 0.00 Bytes 0.00 bits/sec sender
[2022-2-16 15:41:16] [ 5] 0.00-10.03 sec 1.10 GBytes 939 Mbits/sec receiver
[2022-2-16 15:41:16] 11: [ 4] 9.00-10.00 sec 112 MBytes 941 Mbits/sec 0 465 KBytes
[2022-2-16 15:41:16] 11: - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:16] 11: [ ID] Interval Transfer Bandwidth Retr
[2022-2-16 15:41:16] 11: [ 4] 0.00-10.00 sec 1.10 GBytes 944 Mbits/sec 0 sender
[2022-2-16 15:41:16] 11: [ 4] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
[2022-2-16 15:41:16] 11:
[2022-2-16 15:41:16] 11: iperf Done.
[2022-2-16 15:41:16] -----------------------------------------------------------
[2022-2-16 15:41:16] Server listening on 5201
[2022-2-16 15:41:16] -----------------------------------------------------------
[2022-2-16 15:41:17] 33: Connecting to host 192.168.1.33, port 5201
[2022-2-16 15:41:17] Accepted connection from 192.168.1.44, port 46078
[2022-2-16 15:41:17] 33: [ 4] local 192.168.1.3 port 46080 connected to 192.168.1.33 port 5201
[2022-2-16 15:41:17] [ 5] local 192.168.1.4 port 5201 connected to 192.168.1.44 port 46080
[2022-2-16 15:41:18] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:18] [ 5] 0.00-1.00 sec 109 MBytes 913 Mbits/sec
[2022-2-16 15:41:18] 33: [ ID] Interval Transfer Bandwidth Retr Cwnd
[2022-2-16 15:41:18] 33: [ 4] 0.00-1.00 sec 114 MBytes 955 Mbits/sec 0 277 KBytes
[2022-2-16 15:41:19] [ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:19] 33: [ 4] 1.00-2.00 sec 112 MBytes 943 Mbits/sec 0 305 KBytes
[2022-2-16 15:41:20] [ 5] 2.00-3.00 sec 112 MBytes 942 Mbits/sec
[2022-2-16 15:41:20] 33: [ 4] 2.00-3.00 sec 112 MBytes 941 Mbits/sec 0 305 KBytes
[2022-2-16 15:41:21] [ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:21] 33: [ 4] 3.00-4.00 sec 112 MBytes 942 Mbits/sec 0 324 KBytes
[2022-2-16 15:41:22] [ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:22] 33: [ 4] 4.00-5.00 sec 112 MBytes 942 Mbits/sec 0 339 KBytes
[2022-2-16 15:41:23] [ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:23] 33: [ 4] 5.00-6.00 sec 112 MBytes 942 Mbits/sec 0 356 KBytes
[2022-2-16 15:41:24] [ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:24] 33: [ 4] 6.00-7.00 sec 112 MBytes 942 Mbits/sec 0 375 KBytes
[2022-2-16 15:41:25] [ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:25] 33: [ 4] 7.00-8.00 sec 112 MBytes 942 Mbits/sec 0 393 KBytes
[2022-2-16 15:41:26] [ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:26] 33: [ 4] 8.00-9.00 sec 112 MBytes 941 Mbits/sec 0 393 KBytes
[2022-2-16 15:41:27] [ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:27] [ 5] 10.00-10.03 sec 3.41 MBytes 936 Mbits/sec
[2022-2-16 15:41:27] - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:27] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:27] [ 5] 0.00-10.03 sec 0.00 Bytes 0.00 bits/sec sender
[2022-2-16 15:41:27] [ 5] 0.00-10.03 sec 1.10 GBytes 938 Mbits/sec receiver
[2022-2-16 15:41:28] 33: [ 4] 9.00-10.00 sec 112 MBytes 941 Mbits/sec 0 393 KBytes
[2022-2-16 15:41:28] 33: - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:28] 33: [ ID] Interval Transfer Bandwidth Retr
[2022-2-16 15:41:28] 33: [ 4] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0 sender
[2022-2-16 15:41:28] 33: [ 4] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
[2022-2-16 15:41:28] 33:
[2022-2-16 15:41:28] 33: iperf Done.
[2022-2-16 15:41:28] -----------------------------------------------------------
[2022-2-16 15:41:28] Server listening on 5201
[2022-2-16 15:41:28] -----------------------------------------------------------
[2022-2-16 15:41:29] 55: Connecting to host 192.168.1.55, port 5201
[2022-2-16 15:41:29] Accepted connection from 192.168.1.66, port 41710
[2022-2-16 15:41:29] 55: [ 4] local 192.168.1.5 port 41712 connected to 192.168.1.55 port 5201
[2022-2-16 15:41:29] [ 5] local 192.168.1.6 port 5201 connected to 192.168.1.66 port 41712
[2022-2-16 15:41:30] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:30] [ 5] 0.00-1.00 sec 109 MBytes 913 Mbits/sec
[2022-2-16 15:41:30] 55: [ ID] Interval Transfer Bandwidth Retr Cwnd
[2022-2-16 15:41:30] 55: [ 4] 0.00-1.00 sec 114 MBytes 955 Mbits/sec 0 291 KBytes
[2022-2-16 15:41:31] [ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:31] 55: [ 4] 1.00-2.00 sec 112 MBytes 941 Mbits/sec 0 305 KBytes
[2022-2-16 15:41:32] [ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:32] 55: [ 4] 2.00-3.00 sec 112 MBytes 942 Mbits/sec 0 320 KBytes
[2022-2-16 15:41:33] [ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:33] 55: [ 4] 3.00-4.00 sec 112 MBytes 942 Mbits/sec 0 337 KBytes
[2022-2-16 15:41:34] [ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:34] 55: [ 4] 4.00-5.00 sec 112 MBytes 942 Mbits/sec 0 337 KBytes
[2022-2-16 15:41:35] [ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:35] 55: [ 4] 5.00-6.00 sec 112 MBytes 942 Mbits/sec 0 369 KBytes
[2022-2-16 15:41:36] [ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:36] 55: [ 4] 6.00-7.00 sec 112 MBytes 942 Mbits/sec 0 369 KBytes
[2022-2-16 15:41:37] [ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:37] 55: [ 4] 7.00-8.00 sec 112 MBytes 942 Mbits/sec 0 389 KBytes
[2022-2-16 15:41:38] [ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:38] 55: [ 4] 8.00-9.00 sec 112 MBytes 941 Mbits/sec 0 389 KBytes
[2022-2-16 15:41:39] [ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:39] [ 5] 10.00-10.03 sec 3.55 MBytes 934 Mbits/sec
[2022-2-16 15:41:39] - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:39] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:39] [ 5] 0.00-10.03 sec 0.00 Bytes 0.00 bits/sec sender
[2022-2-16 15:41:39] [ 5] 0.00-10.03 sec 1.10 GBytes 938 Mbits/sec receiver
[2022-2-16 15:41:39] 55: [ 4] 9.00-10.00 sec 113 MBytes 951 Mbits/sec 0 600 KBytes
[2022-2-16 15:41:39] 55: - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:39] 55: [ ID] Interval Transfer Bandwidth Retr
[2022-2-16 15:41:39] 55: [ 4] 0.00-10.00 sec 1.10 GBytes 944 Mbits/sec 0 sender
[2022-2-16 15:41:39] 55: [ 4] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
[2022-2-16 15:41:39] 55:
[2022-2-16 15:41:39] 55: iperf Done.
[2022-2-16 15:41:39] -----------------------------------------------------------
[2022-2-16 15:41:39] Server listening on 5201
[2022-2-16 15:41:39] -----------------------------------------------------------
[2022-2-16 15:41:40] 99: Connecting to host 192.168.1.99, port 5201
[2022-2-16 15:41:40] Accepted connection from 192.168.1.22, port 39270
[2022-2-16 15:41:40] 99: [ 4] local 192.168.1.9 port 39272 connected to 192.168.1.99 port 5201
[2022-2-16 15:41:40] [ 5] local 192.168.1.2 port 5201 connected to 192.168.1.22 port 39272
[2022-2-16 15:41:41] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:41] [ 5] 0.00-1.00 sec 109 MBytes 914 Mbits/sec
[2022-2-16 15:41:41] 99: [ ID] Interval Transfer Bandwidth Retr Cwnd
[2022-2-16 15:41:41] 99: [ 4] 0.00-1.00 sec 114 MBytes 955 Mbits/sec 0 288 KBytes
[2022-2-16 15:41:42] [ 5] 1.00-2.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:42] 99: [ 4] 1.00-2.00 sec 112 MBytes 942 Mbits/sec 0 288 KBytes
[2022-2-16 15:41:43] [ 5] 2.00-3.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:43] 99: [ 4] 2.00-3.00 sec 112 MBytes 941 Mbits/sec 0 288 KBytes
[2022-2-16 15:41:44] [ 5] 3.00-4.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:44] 99: [ 4] 3.00-4.00 sec 112 MBytes 942 Mbits/sec 0 305 KBytes
[2022-2-16 15:41:45] [ 5] 4.00-5.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:45] 99: [ 4] 4.00-5.00 sec 112 MBytes 942 Mbits/sec 0 305 KBytes
[2022-2-16 15:41:46] [ 5] 5.00-6.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:46] 99: [ 4] 5.00-6.00 sec 112 MBytes 942 Mbits/sec 0 318 KBytes
[2022-2-16 15:41:47] [ 5] 6.00-7.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:47] 99: [ 4] 6.00-7.00 sec 112 MBytes 943 Mbits/sec 0 349 KBytes
[2022-2-16 15:41:48] [ 5] 7.00-8.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:48] 99: [ 4] 7.00-8.00 sec 112 MBytes 943 Mbits/sec 0 369 KBytes
[2022-2-16 15:41:49] [ 5] 8.00-9.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:49] 99: [ 4] 8.00-9.00 sec 112 MBytes 941 Mbits/sec 0 369 KBytes
[2022-2-16 15:41:50] [ 5] 9.00-10.00 sec 112 MBytes 941 Mbits/sec
[2022-2-16 15:41:50] [ 5] 10.00-10.03 sec 3.28 MBytes 931 Mbits/sec
[2022-2-16 15:41:50] - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:50] [ ID] Interval Transfer Bandwidth
[2022-2-16 15:41:50] [ 5] 0.00-10.03 sec 0.00 Bytes 0.00 bits/sec sender
[2022-2-16 15:41:50] [ 5] 0.00-10.03 sec 1.10 GBytes 939 Mbits/sec receiver
[2022-2-16 15:41:50] 99: [ 4] 9.00-10.00 sec 112 MBytes 941 Mbits/sec 0 369 KBytes
[2022-2-16 15:41:50] 99: - - - - - - - - - - - - - - - - - - - - - - - - -
[2022-2-16 15:41:50] 99: [ ID] Interval Transfer Bandwidth Retr
[2022-2-16 15:41:50] 99: [ 4] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0 sender
[2022-2-16 15:41:50] 99: [ 4] 0.00-10.00 sec 1.10 GBytes 941 Mbits/sec receiver
[2022-2-16 15:41:50] 99:
[2022-2-16 15:41:50] 99: iperf Done.
回复