We used tftp protocol and ethernet cable to send a media file to our remote device. At same time we used tcpdump tool at out remote device.So we saved the communication to a .pcap file.
tcpdump command we used:
tcpdump -i eth0 -s 0 -w video.pcap host <HOST_IP> and udp
We wrote this simple python code to analyze .pcap file and then merge data from frames to a output file
We aim to; Compare output file's binary information and the first media file's binary information. So we can see if there is loss at the communication line or not.
Python Code:
from scapy.all import rdpcap
a = rdpcap('video.pcap')
file = b''
print ( 'Packet Count:' , len(a))
for x in range(0,len(a)):
if (a[x].src=='<HOST>' and a[x].dst=='<DEVICE>' and a[x].proto==17 ): #Filter
for y in range( 4 , len(a[x].load ) ): #We take after fourth element of payload
file = file + a[x].load[y].to_bytes(1, 'big')
print(x , y , a[x].load[y] )
print(file)
with open("video.mp4", "wb") as binary_file:
# Write bytes to file
binary_file.write(file)
The code works and creates the legit output file.But it is really slow.
For example; It takes approximately 3.5 hours to generate a 45 second 1080p 30 FPS .mp4 file from pcap file.