sendip 快速入门

sendip是linux下的命令行发包工具

命令模式:

sendip 网络层 传输层 数据 domain

其中 domain 是目的主机,即此数据包的第一个路由目标,可使用网址和 ip。

常用命令参数:

-d 要携带的数据。使用参数  rN 来产生随机的 N 个字节。

-f从文件中读取要携带的数据。

-p 指定要使用的网络协议。

-v 打印整个发出的数据包。

示例:

sendip -v -p  ipv4 -id 14.225.177.39 -p udp -f test www.baidu.com
sendip -p ipv4  -is 192.168.1.2 -id 192.168.1.1 -p icmp -d -x89ABCDEF www.baidu.com

注:domain 字段可以和 -id 的值不同,此时该数据包在主机发出后的第一个路由目标是 domain 字段指示的地址,但该数据的的目的 ip 地址为 -id 的值。

程序示例:

在工业控制中经常需要处理周期性产生的网络数据流,下面用sendip来模拟这种数据流的产生。

新建一个shell脚本文件

$ vim send.sh

输入内容如下:

#!/bin/bash

cd /root/Desktop/

send_1(){
while true
do	
	sendip -p ipv4 -is 192.168.1.2 -id 192.168.1.1 -p udp -f message 192.168.1.222
	sleep 0.001
done
}

send_2(){
while true
do	
	sendip -p ipv4 -is 192.168.1.2 -id 192.168.1.1  -p udp -f message 192.168.1.222
	sleep 0.01
done			
}

send_3(){
while true
do
    sendip -p ipv4 -is 192.168.1.2 -id 192.168.1.1 -p udp -f message 192.168.1.222
    sleep 0.1
done
}

send_1 & send_2 & send_3

这里建立了三条数据流,周期分别是0.001s,0.01s,0.1s。

新建 message 文件,可在其中输入想要发送的内容

$vim message

message内容如下

hello world!

可搭建两台虚拟机进行测试,在一台虚拟机上使用命令

$./send.sh

运行此脚本,在接收端虚拟机上可以使用 wireshark 截获如下数据包

 

                                                  


版权声明:本文为zh_94原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。