I am trying to read PCAP files on matlab. Can anyone suggest how to do so?

댓글 수: 5

James
James 2020년 3월 3일
I recently decided to do this also. I've found pcap2matlab code mentioned by Punjitha not very functional.
It requires TShark installed AND on your path. TShark is part of wireshark, and was not initially part of my installation for some reason.
The help was unclear, and a challenge to read through.
Further I'm interested in "live" analysis as the data streams in, so I've ended up using a different part of wireshark (editcap) to convert the packet data to a text based format and wrote my own parser.
I'd be happy to share if you're intersted, but its (very) poorly tested. The part that works can load hex text ethernet frame (k12 text) output from wireshark:editcap into ipv4, and udp. It returns a cell array of packets structs.
Nishu Vidyarthi
Nishu Vidyarthi 2020년 3월 3일
I could not find any useful way to to this either. Ended up using Tshark and finally wrote a python code to separate the frame layers of the data. However I would definitely like to know your method.
James
James 2020년 3월 4일
편집: James 2020년 3월 4일
Well, okay, I've cleaned up my messy bits(a little), and apologize in advance for minimal testing. I read the bare minimum of documentation to get what I wanted done so many pieces are incomplete. Further, this was a home project, so my work was done in gnu octave, and I didnt bother to check that it ran the same at work.
All the disclaimers aside, this code ran fast enough for me written in pure matlab, so I was happy. I'm thinking of just learning the pcapng format since I just about had to drop to binary packet handling here, and it doesnt seem like it'd be much more work.
If you need copyright licensing ... this is free, it will destroy the computer of anyone whom runs it, encourage people to blame me, but only for succes .
Tolga Ulupinar
Tolga Ulupinar 2022년 2월 1일
Hi James. I have some problems in your scripts. In capture read " error using hex2num Too many input arguments" . Can you help me for this error. How can ı fix this error. I used test_packet.txt
Walter Roberson
Walter Roberson 2022년 2월 1일
편집: Walter Roberson 2022년 2월 1일
I see that @James mentioned that he wrote the code using Octave. The Octave hex2num() supports passing a class as the second parameter, but MATLAB does not.
I think you can change the hex2udp line
udp.(fields{fn})=hex2num(udp.(fields{fn}),'uint16');
to
udp.(fields{fn}) = uint16(sscanf(udp.(fields{fn}), '%x'));
This would possibly have slightly different behaviour in cases where the input somehow had spaces or non-hex characters instead of the expect hex output; I do not have access to Octave to test its behaviour in detail (and there is the big question of what would be most reasonable to have happen in that circumstance.)

댓글을 달려면 로그인하십시오.

 채택된 답변

Pujitha Narra
Pujitha Narra 2020년 2월 24일
편집: Pujitha Narra 2026년 5월 14일 7:21

1 개 추천

You can use this feature from the Wireless Network Toolbox: https://www.mathworks.com/help/wireless-network/ref/pcapreader.html

추가 답변 (2개)

michael
michael 2020년 6월 20일

0 개 추천

Hello,
Please see my response here on how to use pcap2matlab
Idin Motedayen-Aval
Idin Motedayen-Aval 2024년 6월 3일

0 개 추천

For completeness:
If you have access to 5G Toolbox, there is built-in pcapReader function that has been available since R2021b.

카테고리

도움말 센터File Exchange에서 Get Started with WLAN Toolbox에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 2월 20일

편집:

2026년 5월 14일 7:21

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by