使用说明
本程序具有UDP抓包、分析丢包、发包、组播转发等功能.
UDP抓包、发包利用libcap实现(编译libpcap源码,生成静态库,然后链接静态库的方式)
支持linux平台
##编译
>cd ur_dir
>make
##支持功能
从指定的地址接收并保存成cap文件(可定时和分析丢包)
支持直接从指定的地址接收流并直接保存成mpg文件(可定时和分析丢包)
将cap文件还原成流发送到指定的组播/单播地址(支持对单个文件的循环发送,还可以设置丢包率)
支持将cap文件转换成可播放的ts文件
支持分析指定文件(cap,ts)或指定组播/单播流是否存在RTP丢包和TS丢包
支持通过指定组播地址和端口获取源IP地址和端口
支持后台运行
支持自动分析RTP头长度(在不指定-f参数的情况下)
支持组播/单播转发到新的组播/单播地址(并可以指定丢包率)
支持分析包间隔是否超过设定的阈值
##参数说明
####Usage
./ur [ACTION] [OPTION]
####ACTION
--catch,-c 抓取指定组播/单播流,将其保存成cap文件或ts文件(可边抓边分析丢包).
--send,-s 将cap文件数据发往指定组播/单播地址和端口.
--convert,-n 将cap文件转成ts文件(可边转边分析丢包).
--analyze,-a 分析指定文件(cap,ts)或指定组播/单播流是否存在RTP丢包和TS丢包.
--print-ip,-p 指定组播地址,获取其对应的源IP地址和端口(发出组播的主机的IP地址和端口).
--transfer,-S 组播/单播转发到新的组播/单播地址(支持指定丢包率).
####OPTION
--inputfile,-i filepath 发包、cap转ts、分析丢包时需要的输入文件路径
--multicast,-m ip:port 抓包、分析组播流丢包时需要指定的组播/单播地址和端口
--out2cap,-o output_file_path 进行抓cap包时的输出文件路径
--out2ts,-t output_file_path 抓mpg包、cap转ts时的输出文件路径
--losslog,-l loss_logfile_path 进行丢包分析,并将丢包信息写入丢包日志
--offset,-f offset 设定数据的偏移位置(一般设定为RTP头的长度,如'convert'时,cap文件带RTP头,且长度为24,则-f 24)
--device,-d nic_name 指定抓包和分析组播流丢包时的网卡设备(如eth0, eth1, bond0)
--timer,-T minute 设置定时抓包的时间,单位:分钟(默认为0,表示不限时间)
--newaddress,-w new_ip:new_port 新的组播或单播地址
--lossrate,-R pkt_loss_rate 丢包率百分比,默认0%,取值范围为0-100
--interval,-I pkt_interval 最大包间隔, 用于最大包间隔检查, 单位: us(1s = 1000ms = 1000000us).
--repeat,-r 循环发送cap文件
--background,-b ur在后台运行
--version,-v 获取版本信息
--help,-h 显示帮助
##使用示例
从指定组播地址和端口抓cap包(可边抓边分析丢包)
./ur --catch -m 230.9.9.103:6000 -o 1.cap [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
从指定组播地址和端口抓包保存成ts文件(可边抓边分析丢包)
./ur --catch -m 230.9.9.103:6000 -t 1.mpg [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
将cap文件发往指定组播地址和端口(可循环发送,可设置丢包率)
./ur --send -i 1.cap -m 230.9.9.103:6000 [-f 24] [-R 5] [-r] [-b]
将cap文件转成ts文件(可边转边分析丢包)
./ur --convert -i 1.cap -t 1.mpg [-l loss.log] [-f 24] [-b]
分析指定文件(cap,ts)或指定组播流是否存在RTP丢包和TS丢包
./ur --analyze -i 1.cap -l loss.log [-f 24] [-I 1000] [-b]
./ur --analyze -t 1.mpg -l loss.log [-b]
./ur --analyze -m 230.9.9.103:6000 -l loss.log [-f 24] [-d eth1] [-b]
获取指定组播地址和端口对应的源IP地址和端口
./ur --print-ip -m 230.9.9.103:6000 [-d eth1]
组播转单播
./ur --transfer -m 230.9.9.103:6000 -w 172.19.148.236:1234
组播转组播
./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234
组播转组播,丢包率设为3%
./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234 -R 3
README
##Compile
>cd ur_dir
>make
##Usage
./ur [ACTION] [OPTION]
###ACTION
--catch,-c Capture a stream as a cap file or ts file.
--send,-s Send the cap file to multicast/unicast address.
--convert,-n Convert cap file to ts stream file.
--analyze,-a Analyze a cap file or ts file or a stream exist packet loss or not.
--print-ip,-p Get the source ip and port of multicast address.
--transfer,-S Transfer a udp stream from multicast/unicast address to another address.
##OPTION
--inputfile,-i filepath Input file for 'send' or 'convert' or 'analyze'
--multicast,-m ip:port Multicast/unicast address and port supply to 'catch' or 'analyze'
--out2cap,-o output_file_path The cap file 'catch' to save to
--out2ts,-t output_file_path The ts file 'catch' or 'convert' to save to
--losslog,-l loss_logfile_path The logfile of packet loss info
--offset,-f offset Assigned the offset for 'catch', 'send', 'convert' or 'analyze'
--device,-d nic_name The device used for capture (e.g. eth0, eth1, bond0)
--timer,-T minute Set the 'catch' time('0' indicates no time limit)
--newaddress,-w new_ip:new_port New address and port supply to 'transfer'
--lossrate,-R pkt_loss_rate Packet loss rate, default is 0%, the value range is 0 to 5.
--interval,-I pkt_interval Max packet interval check, unit: us(1s = 1000ms = 1000000us).
--repeat,-r Repeat to play the cap file
--background,-b Run the programe in background
--version,-v Get version of this program
--help,-h Print usage of this program
##EXAMPLE
Dump a stream as a cap file
./ur --catch -m 230.9.9.103:6000 -o 1.cap [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
Dump a stream as a mpg file
./ur --catch -m 230.9.9.103:6000 -t 1.mpg [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
Send the cap file to multicast address
./ur --send -i 1.cap -m 230.9.9.103:6000 [-f 24] [-R 5] [-r] [-b]
Convert a cap file to ts file
./ur --convert -i 1.cap -t 1.mpg [-l loss.log] [-f 24] [-b]
Analyze a cap file or ts file or a stream whether the packet loss occurs
./ur --analyze -i 1.cap -l loss.log [-f 24] [-I 1000] [-b]
./ur --analyze -t 1.mpg -l loss.log [-b]
./ur --analyze -m 230.9.9.103:6000 -l loss.log [-f 24] [-d eth1] [-b]
Get the source ip and port of multicast address
./ur --print-ip -m 230.9.9.103:6000 [-d eth1]
Transfer a udp stream from multicast address to unicast address:
./ur --transfer -m 230.9.9.103:6000 -w 172.19.148.236:1234
Transfer a udp stream from a multicast to another multicast:
./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234
Transfer a udp stream from a multicast to another multicast with 3% pkt loss:
./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234 -R 3