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 -p udp -d message 192.168.1.222
	sleep 0.001
done
}

send_2(){
while true
do	
	sendip -p ipv4 -p udp -d message 192.168.1.222
	sleep 0.01
done			
}

send_3(){
while true
do
        sendip -p ipv4 -p udp -d 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 截獲如下數據包

 

                                                  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章