Skip to content

Instantly share code, notes, and snippets.

@4ft35t
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4ft35t/fc56efe306d54dd735d7 to your computer and use it in GitHub Desktop.
Save 4ft35t/fc56efe306d54dd735d7 to your computer and use it in GitHub Desktop.
Get HTTP request by tshark from pcap
#!/bin/bash
######
# https://ask.wireshark.org/questions/14811/follow-tcp-stream-with-tshark-still-can-not-in-batch-mode
# Useage: http_header.sh *.pcap
######
filter='http'
files=$(ls $@)
filter_http () {
# TCP stream IDs
TCP_STREAMS=$(tshark -r "$files" -2 -R "$filter" -T fields -e tcp.stream|sort -n -u)
# filter by each stream ID
for stream in ${TCP_STREAMS}
do
tshark -r "$files" -q -z follow,tcp,ascii,$stream
done
}
for f in $files
do
filter_http $f |awk -f http-request.awk
done
# content of http-request.awk
:<<awk
BEGIN{flag=0}
/ HTTP\//{print "## BEGIN";print;flag=1;next}
flag==1 && !/^\s*[0-9]+$/{print;next}
flag==1 && /^\s*[0-9]+$/{print "## END";flag=0}
awk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment