diff options
author | Nikita Stupin <18281368+nikitastupin@users.noreply.github.com> | 2020-04-10 21:07:21 +0300 |
---|---|---|
committer | Nikita Stupin <18281368+nikitastupin@users.noreply.github.com> | 2020-04-10 21:07:21 +0300 |
commit | 743cb949e8f5df5029b4b364d3d9692d1b6eb5d4 (patch) | |
tree | bc92d18bca0200b4c7d7e6da3dd622c9873953dd /mitmproxy/tools/console/common.py | |
parent | 0d9e517c064ca3992fac83c3a1ec6e4284221e72 (diff) | |
download | mitmproxy-743cb949e8f5df5029b4b364d3d9692d1b6eb5d4.tar.gz mitmproxy-743cb949e8f5df5029b4b364d3d9692d1b6eb5d4.tar.bz2 mitmproxy-743cb949e8f5df5029b4b364d3d9692d1b6eb5d4.zip |
Display TCP flows at flow list!
Diffstat (limited to 'mitmproxy/tools/console/common.py')
-rw-r--r-- | mitmproxy/tools/console/common.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py index 3dce8363..9ed5795f 100644 --- a/mitmproxy/tools/console/common.py +++ b/mitmproxy/tools/console/common.py @@ -10,6 +10,7 @@ import urwid import urwid.util from mitmproxy.utils import human +from mitmproxy.tcp import TCPFlow # Detect Windows Subsystem for Linux IS_WSL = "Microsoft" in platform.platform() @@ -507,7 +508,64 @@ def raw_format_table(f): return urwid.Pile(pile) +# TODO: this function can replace repeated code in raw_format_table() in the future +def raw_format_cursor(f): + cursor = [" ", "focus"] + if f["focus"]: + cursor[0] = ">" + return fcol(*cursor) + + +# TODO: this function can replace repeated code in raw_format_table() in the future +def raw_format_timestamp(timestamp, extended): + if extended: + s = human.format_timestamp(timestamp) + else: + s = datetime.datetime.fromtimestamp(time.mktime(time.localtime(timestamp))).strftime("%H:%M:%S") + return fcol(s, "title") + + +@lru_cache(maxsize=800) +def raw_format_tcp_table(f): + # If you'll remove this line TypeError: unhashable type: 'dict' will occur + # because of @lru_cache + f = dict(f) + + pile = [] + + columns = [ + raw_format_cursor(f), + raw_format_timestamp(f["timestamp_start"], f["extended"]), + fcol("TCP", "tcp"), + fcol(f["client"], "client"), + fcol("---", "direction"), + fcol(f["server"], "server"), + ] + + m = [c for c in columns] + + pile.append(urwid.Columns(m, dividechars=1)) + + return urwid.Pile(pile) + + def format_flow(f, focus, extended=False, hostheader=False, cols=False, layout='default'): + + if isinstance(f, TCPFlow): + d = dict( + focus=focus, + extended=extended, + timestamp_start=f.timestamp_start, + client=human.format_address(f.client_conn.address), + server=human.format_address(f.server_conn.address), + ) + + # If you'll remove this line TypeError: unhashable type: 'dict' will occur + # because of @lru_cache. + t = tuple(sorted(d.items())) + + return raw_format_tcp_table(t) + acked = False if f.reply and f.reply.state == "committed": acked = True |