How to Read a .pcapng file's content directly from memory instead of from disk? #613
Unanswered
barmanroys
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using the file capture API of pyshark like this.
But now, I have another use case where the file content can be made available to me only as an array of bytes, or as UploadFile class of FastAPI. As in this link.
https://fastapi.tiangolo.com/tutorial/request-files/
Basically, the user (frontend) will upload the pcapng file and then I need to read it as an array of packet, getting the same capture object I can get from a pcapng file stored locally. If necessary, I can read the file content as byte in memory as well, like this.
So how to get the capture object from the user uploaded file? I have the idea of dumping the file_content on disk as a temporary file and then reading it via FileCapture, which is clearly suboptimal and bug prone.
But is there a better way to get the capture object directly from in-memory bytes via pyshark? I tried
capture=ps.InMemCapture(file_content) # Failed because capture is of length 0
but it failed to read any packet.
Beta Was this translation helpful? Give feedback.
All reactions