inspired by @sch here is a bash version:
file=cap.pcap
$tshark -Tfields -e tcp.stream \
-e frame.time_epoch \
-e ip.src \
-e tcp.srcport \
-e ip.dst \
-e tcp.dstport -r $file |
sort -snu |
while read -a f; do
[[ "${f[5]}" ]] || continue # sometimes there is no stream number ex. UDP
fileout=$(echo ${f[0]}__${f[1]}__${f[2]}__${f[3]}__${f[4]}__${f[5]} | tr -d '\r' )
$tshark -r $file -2R "tcp.stream == ${f[0]}" -w "$fileout.pcap"
done
read
the filename will be like that: stream number__time__source IP__port__destination IP__port.pcap
tr -d '\r'
is for windows users, because tshark in windows output CR LF.
Edit:
this solution with tshark is so slow but sure.
SplitCap is super fast but when there is an error in some packet it crashes, while tshark only inform you about the error but continue :
tshark: The file "cap.pcap" appears to have been cut short in the middle of a packet.
and finally there is PcapSplitter which is super fast too but it need the winpcap driver, it doesn't work with the npcap driver in windows.
But there is a solution to SplitCap:
using pcapfix I can fix the corrupt packets then SplitCap never crashes again. and this is what I m using now, because tshark is so slow in spliting.
and a solution to PcapSplitter I did was injecting the winpcap dll using any method but while we have SplitCap why do it?