使用 Scapy 解码基于 UDP 的 RTP [英] Decode RTP over UDP with Scapy

查看:91
本文介绍了使用 Scapy 解码基于 UDP 的 RTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Scapy 2.3.2 解码(和操作)UDP 上的 RTP?

我有一个名为 rtp.pcap 的捕获文件,其中包含到 224.0.1.11:5016 的 RTP 音频流.当您启用 RTP over UDP 协议(​​默认关闭)时,Wireshark 会正确解码流.但是,我想做自动数据包操作,所以我想用 Scapy 对其进行解码.

目前,尽管有 RTP 层,但 Scapy 无法识别 RTP:

<预><代码>>>>from scapy.all import RTP #显示我的版本安装了RTP层>>>pkts = sniff(offline="rtp.pcap", filter="udp dst 端口 5016")>>>pkts[0].show()[...]###[ UDP ]###运动= 5004端口= 5016len= 196 <-- 那是一个音频包[...]###[ 生的 ]###负载= ...[...]

解决方案

以下代码强制将 UDP Payload 解释为 RTP:

from scapy.all 导入 RTP对于 pkts 中的 pkt:if pkt["UDP"].dport==5016: # 确保它实际上是 RTPpkt["UDP"].payload = RTP(pkt["Raw"].load)

How can I decode (and manipulate) RTP over UDP with Scapy 2.3.2?

I have a capture file called rtp.pcap which contains an RTP audiostream to 224.0.1.11:5016. Wireshark correctly decodes the stream when you enable the RTP over UDP protocol (default off). However, I want to do automatic packet manipulation, so I would like to decode it with Scapy.

Currently, Scapy does not recognize RTP, although there is an RTP layer:

>>> from scapy.all import RTP # shows that RTP layer is installed in my version
>>> pkts = sniff(offline="rtp.pcap", filter="udp dst port 5016")
>>> pkts[0].show()
[...]
###[ UDP ]###
    sport= 5004
    dport= 5016
    len= 196 <-- thats an audio pkt
[...]
###[ Raw ]###
       load= ...
[...]

解决方案

The following code forces the UDP Payload to be interpreted as RTP:

from scapy.all import RTP
for pkt in pkts:
    if pkt["UDP"].dport==5016: # Make sure its actually RTP
        pkt["UDP"].payload = RTP(pkt["Raw"].load)

这篇关于使用 Scapy 解码基于 UDP 的 RTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆