简单介绍下指定源多播发放的和抓取指定源多播数据的工具。

抓取指定源多播数据

安装

1
2
3
4
5
sudo apt update && sudo apt install tcpdump -y
# or
sudo apt update && sudo apt install -y termshark
# or termshark 基于 tshark,提供类似于wireshark的交互式界面,但是基于termial
sudo apt update && sudo apt install -y tshark

抓取

1
2
3
4
5
6
7
8
9
# 在网卡 eth0 上,捕获由特定源主机(172.20.177.107)发送到指定多播组(239.1.1.1)且目标端口为 5001 的 UDP 数据包
# -nn 禁用域名和端口名解析,预防延迟
# 加上 -X(大写)参数。它会在屏幕右侧以人类可读的明文(ASCII)形式显示数据,左侧显示对应的十六进制,非常适合分析自定义协议或文本数据。
sudo tcpdump -nnX -i eth0 src host 172.20.177.107 and dst host 239.1.1.1 and udp port 5001

# or
sudo termshark -i eth0 -Y "ip.src == 172.20.177.107 and ip.dst == 239.1.1.1 and udp.port == 5001"
# or
sudo tshark -i eth0 -f "src host 172.20.177.107 and dst host 239.1.1.1 and udp port 5001"

发送指定源多播数据

安装

1
sudo apt update && sudo apt install socat -y

发送

1
2
3
4
5
6
# 发送单条数据
# 通过 172.20.177.107 这个网卡 IP,向多播组 239.1.1.1 的 5001 端口发送一个包含 "hello, socat" 的 UDP 组播数据包
echo "hello, socat" | socat - UDP4-DATAGRAM:239.1.1.1:5001,bind=172.20.177.107

# 循环发送
while true; do echo "Test Packet" | socat - UDP4-DATAGRAM:239.1.1.1:5001,bind=172.20.177.107; sleep 1; done