Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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