1 Star 0 Fork 2

-卓然- / udp_relay

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

使用说明

  • 本程序具有UDP抓包、分析丢包、发包、组播转发等功能.
  • UDP抓包、发包利用libcap实现(编译libpcap源码,生成静态库,然后链接静态库的方式)
  • 支持linux平台

##编译

>cd ur_dir
>make

如果编译libpcap过程中出现错误,请参考http://blog.csdn.net/mao_shuo/article/details/8866554

##支持功能

  1. 从指定的地址接收并保存成cap文件(可定时和分析丢包)
  2. 支持直接从指定的地址接收流并直接保存成mpg文件(可定时和分析丢包)
  3. 将cap文件还原成流发送到指定的组播/单播地址(支持对单个文件的循环发送,还可以设置丢包率)
  4. 支持将cap文件转换成可播放的ts文件
  5. 支持分析指定文件(cap,ts)或指定组播/单播流是否存在RTP丢包和TS丢包
  6. 支持通过指定组播地址和端口获取源IP地址和端口
  7. 支持后台运行
  8. 支持自动分析RTP头长度(在不指定-f参数的情况下)
  9. 支持组播/单播转发到新的组播/单播地址(并可以指定丢包率)
  10. 支持分析包间隔是否超过设定的阈值

##参数说明

####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                             显示帮助

##使用示例

  1. 从指定组播地址和端口抓cap包(可边抓边分析丢包)

     ./ur --catch -m 230.9.9.103:6000 -o 1.cap [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
  2. 从指定组播地址和端口抓包保存成ts文件(可边抓边分析丢包)

     ./ur --catch -m 230.9.9.103:6000 -t 1.mpg [-l loss.log] [-f 24] [-d eth1] [-T 5] [-b]
  3. 将cap文件发往指定组播地址和端口(可循环发送,可设置丢包率)

     ./ur --send -i 1.cap -m 230.9.9.103:6000 [-f 24] [-R 5] [-r] [-b]
  4. 将cap文件转成ts文件(可边转边分析丢包)

     ./ur --convert -i 1.cap -t 1.mpg [-l loss.log] [-f 24] [-b]
  5. 分析指定文件(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]
  6. 获取指定组播地址和端口对应的源IP地址和端口

     ./ur --print-ip -m 230.9.9.103:6000 [-d eth1]
  7. 组播转单播

     ./ur --transfer -m 230.9.9.103:6000 -w 172.19.148.236:1234
  8. 组播转组播

     ./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234
  9. 组播转组播,丢包率设为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

  1. 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]
  2. 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]
  3. Send the cap file to multicast address

     ./ur --send -i 1.cap -m 230.9.9.103:6000 [-f 24] [-R 5] [-r] [-b]
  4. Convert a cap file to ts file

     ./ur --convert -i 1.cap -t 1.mpg [-l loss.log] [-f 24] [-b]
  5. 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]
  6. Get the source ip and port of multicast address

     ./ur --print-ip -m 230.9.9.103:6000 [-d eth1]
  7. Transfer a udp stream from multicast address to unicast address:

     ./ur --transfer -m 230.9.9.103:6000 -w 172.19.148.236:1234
  8. Transfer a udp stream from a multicast to another multicast:

     ./ur --transfer -m 230.9.9.103:6000 -w 239.1.1.100:1234
  9. 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

空文件

简介

一个利用libcap实现的linux下具有UDP抓包、分析丢包、发包等功能的小工具 展开 收起
C++
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/js2854/udp_relay.git
git@gitee.com:js2854/udp_relay.git
js2854
udp_relay
udp_relay
master

搜索帮助