Skip to content

Instantly share code, notes, and snippets.

@lanuma
Created December 16, 2016 20:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save lanuma/90bdb4ec1934f9fc50fe499ebbc8a0cf to your computer and use it in GitHub Desktop.
Save lanuma/90bdb4ec1934f9fc50fe499ebbc8a0cf to your computer and use it in GitHub Desktop.
Extract RTP from pcap to raw and convert to wav
#!/bin/bash
pcap_file="voip.pcap"; #nama file pcap
audio_output="suara.wav"; #output audio
raw_file="suara.raw"; #nama raw file hasil extract
if [ $EUID -ne 0 ]; then
echo "This script must be run as root";
exit 1;
fi
if [ -x /usr/bin/tshark ]; then
ssrc=$(tshark -n -r $pcap_file -R rtp -T fields -e rtp.ssrc -Eseparator=, | sort -u | awk 'FNR ==1 {print}')
echo "SSRC: ";
echo $ssrc;
tshark -n -r $pcap_file -R rtp -R "rtp.ssrc == $ssrc" -T fields -e rtp.payload | tee payloads;
else
echo "tshark tidak ditemukan";
fi
for payload in `cat payloads`;
do
IFS=:;
for byte in $payload;
do
printf "\\x$byte" >> $raw_file;
done;
done
if [ -x /usr/bin/sox ]; then
echo 'sox has converted pcap to wav file';
sox -t raw -r 8000 -v 4 -c 1 -U $raw_file $audio_output;
else
echo "sox tidak ditemukan";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment