Skip to content

Instantly share code, notes, and snippets.

@zengxinhui
Created April 17, 2024 04:31
Show Gist options
  • Save zengxinhui/5c1b153d986fc6270843f9b19a0f18b4 to your computer and use it in GitHub Desktop.
Save zengxinhui/5c1b153d986fc6270843f9b19a0f18b4 to your computer and use it in GitHub Desktop.
group by tcp stream and output the last 10 packets captured to see how a connection ended.
tshark -r xyz.pcapng -Y "tcp.port != 445" -T fields -e tcp.stream -e frame.time_relative -e ip.src -e ip.dst -e _ws.col.info | sort -V | awk 'BEGIN {
prev = 0;
count = 0;
} {
buffer[NR % 11] = $0;
if ($1 != prev) {
for (i = NR-count; i<NR; i++)
print buffer[i % 11];
print "";
prev = $1;
count = 1
} else {
if (count<10)
count++;
}
}
END {
for (i = NR-count; i<NR; i++)
print buffer[i % 11];
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment