New Model #3509 » pcap2stream.py
1 |
#! /usr/bin/python
|
---|---|
2 |
|
3 |
# process the output of a tshark stream to strip blank lines and re-join folded
|
4 |
# lines
|
5 |
|
6 |
import sys |
7 |
|
8 |
lineout = "" |
9 |
lastdir = "X" |
10 |
lineno = 0 |
11 |
|
12 |
for line in sys.stdin: |
13 |
lineno += 1 |
14 |
line = line.replace('\n', '') # chomp |
15 |
if (len(line) == 0): |
16 |
continue
|
17 |
toks = line.split("\t") |
18 |
if (toks[0] == "0x00000002"): # some kind of control msg |
19 |
toks[0] = "C" |
20 |
elif (toks[0] == "0x00000003"): # this is bulk in/out data |
21 |
toks[0] = "D" |
22 |
else: |
23 |
print("Bogus USB %s at line %d" % (toks[0], lineno)) |
24 |
continue
|
25 |
if (toks[1] == "host"): # We are the host so we do the writing... |
26 |
toks[1] = "W" |
27 |
else: |
28 |
toks[1] = "R" |
29 |
|
30 |
if (toks[0] == "C"): |
31 |
if (len(lineout) > 0): |
32 |
print("%s: %s" % (lastdir, lineout)) |
33 |
lineout = "" |
34 |
lastdir = "X" |
35 |
else: |
36 |
if (toks[1] == lastdir): |
37 |
if (len(toks) > 2): |
38 |
lineout += (" " + toks[2].replace(":", ' ')) |
39 |
else: |
40 |
if (len(lineout) > 0): |
41 |
print("%s: %s" % (lastdir, lineout)) |
42 |
lastdir = toks[1] |
43 |
lineout = toks[2].replace(":", ' ') |
44 |
if (len(lineout) > 0): |
45 |
print("%s: %s" % (lastdir, lineout)) |