-
Notifications
You must be signed in to change notification settings - Fork 4
/
tshark-http2urls.awk
executable file
·62 lines (59 loc) · 1.47 KB
/
tshark-http2urls.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/awk -f
# Shows URLs from a tshark -O http dump
BEGIN {
FS = "[ :]+";
OFS = "\t";
}
function find(regex, haystack) {
haystack = $0;
regex = "^ *\\[" regex ": ";
if (haystack ~ regex) {
sub(regex, "", haystack); sub(/\]$/, "", haystack);
$0 = haystack;
return 1;
}
return 0;
}
/^Frame / {
frame_no = $2;
in_request = 0;
in_response = 0;
}
next_http {
if ($2 ~ /^HTTP\//) { # response
if ($3 == 200) {
in_request = 0;
in_response = 1;
}
} else { # request
if ($2 == "GET") {
in_request = 1;
in_response = 0;
}
}
next_http = 0;
}
/^Hypertext Transfer Protocol/ { next_http = 1; }
in_request && find("Full request URI") {
urls[frame_no] = $0;
}
in_response {
n = split("Content-Length Last-Modified", header_names, " ");
for (i = 1; i <= n; i++) {
header_name = header_names[i];
if ($2 == header_name) {
sub("^ *" header_name ": ", ""); sub(/\\r\\n$/, "");
headers[header_name, frame_no] = $0;
}
}
}
# Print response if a request matched this frame number
in_response && find("Request in frame") && urls[$1] {
req_frame_no = $1;
#printf("%-7d ", frame_no);
printf("%10d %-29s %s\n",
headers["Content-Length", frame_no],
headers["Last-Modified", frame_no],
urls[req_frame_no]);
}
# vim: set sw=4 et ts=4: