extract-tcp.sh 804 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. # Usage: ./extract-tcp.sh input.pcap output.txt
  3. if [ "$#" -ne 2 ]; then
  4. echo "Usage: $0 <input.pcap> <output.txt>"
  5. exit 1
  6. fi
  7. INPUT="$1"
  8. OUTPUT="$2"
  9. # Extract TCP packet information with headers and payload data
  10. tshark -r "$INPUT" -Y "tcp" -T fields \
  11. -e data \
  12. -e frame.number \
  13. -e frame.time_relative \
  14. -e ip.src \
  15. -e ip.dst \
  16. -e tcp.srcport \
  17. -e tcp.dstport \
  18. -e tcp.seq \
  19. -e tcp.ack \
  20. -e tcp.flags \
  21. -e tcp.flags.syn \
  22. -e tcp.flags.ack \
  23. -e tcp.flags.fin \
  24. -e tcp.flags.reset \
  25. -e tcp.flags.push \
  26. -e tcp.len \
  27. -E header=y \
  28. -E separator="|" > "$OUTPUT"
  29. echo "TCP packet analysis written to $OUTPUT"
  30. echo "Format: HexData|Frame#|Time|SrcIP|DstIP|SrcPort|DstPort|Seq|Ack|Flags|SYN|ACK|FIN|RST|PSH|DataLen"