从 pcap 会话中提取 RTP 流

问题描述

我正在研究一种使用(最好)Python 从 pcap 会话文件中提取一个流的方法。我阅读了许多问题、链接和教程,例如:

How to convert pcap that contains a RTP stream to .raw 来自 3 年前

AudioScraper by Brian Warmer

pcap2wav

AudioScraper 确实允许我从 pcap 中提取 RTP 流,但是我有 4 个 RTP 流,我不知道提取了哪一个。 pcap2wav 能够选择特定的流。在这两种情况下,当我以 audacity 播放输出文件时,声音都无法识别。

直到今天,我仍在尝试找到一种使用 Python 从 pcap 文件中提取特定 RTP 流的自动化方法..

编辑 1

我放弃将自己限制在 Python 答案中。我使用 shell 脚本找到了 Brian Warner 的这个答案:

ssrc=$(sudo tshark -n -r "capture.pcap" -Y rtp -T fields -e rtp.ssrc -Eseparator=,| sort -u)
# [-n disable network object name resolution] 
# [-r read file]
# [-Y read filter applied during first pass. Packets not matching the filter are not considered for future passes]
# [-T format of the output when viewing decoded packet data. fields specified with the -e option]

echo $ssrc
# 0x170e45b8 0x210f90ea 0x302a4ef0 0x6c1acefa

sudo tshark -n -r "capture.pcap" -Y rtp -Y "rtp.ssrc==$ssrc" -T fields -e rtp.payload | tee payloads
for payload in `cat payloads`; do 
  IFS=:;
  
  for byte in $payload;do 
    printf"\\x$byte" >> sound.raw;
  done;
done;

sudo sox -t raw -r 8000 -c 1 sound.raw capture3d.wav

不幸的是它不起作用...

Running as user "root" and group "root". This could be dangerous.
0x170e45b8 0x210f90ea 0x302a4ef0 0x6c1acefa
Running as user "root" and group "root". This could be dangerous.
tshark: "0x210f90ea" was unexpected in this context.
sox FAIL formats: can't open input file `sound.raw': No such file or directory

我对shell知之甚少,你能发现我的错误吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)