A pcap file is downloaded from url with the help of Python (2.7.9) Requests library:
import requests
response = requests.get('http://example.com/path/1.pcap', stream=True)
According to documentation response.raw is a file-like object and my goal is to process the downloaded file without saving it to disk.
I first looked at Scapy and Pyshark libraries for .pcap file parsing but their functions (rdpcap and FileCapture) accept file path string as an argument. pcap.Reader from dpkt library accepts a file object. The first try pcap=dpkt.pcap.Reader(resonse.raw) gave an error:
AttributeError: 'HTTPResponse' object has no attribute 'name'
Name attribute was added:
setattr(response.raw,'name', 'test.pcap')
After that pcap=dpkt.pcap.Reader(resonse.raw) didn't give any errors but pcap.readpkts() failed with
io.UsupportedOperation: seek
And indeed response.raw.seekable() returns False.
I tried setting response.raw.decode_content = True but that didn't help.
Is there a solution for processing the object the way I'm trying? Maybe additional request parameters are required to get a seekable response object?
By the way, if response object is written to file (shutil.copyfileobj(response.raw,file)), dpkt succeeds in working with that file afterwards.