tcpflowy 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ import os
2
+ import sys
3
+
4
+
5
+ class ConsoleStyle:
6
+ """Provides ANSI terminal color formatting with automatic or manual disable support."""
7
+
8
+ ENABLED = sys.stdout.isatty() and os.environ.get("NO_COLOR") is None
9
+
10
+ RESET = "\033[0m"
11
+ BOLD = "\033[1m"
12
+ DIM = "\033[2m"
13
+
14
+ RED = "\033[91m"
15
+ GREEN = "\033[92m"
16
+ YELLOW = "\033[93m"
17
+ BLUE = "\033[94m"
18
+ MAGENTA = "\033[95m"
19
+ CYAN = "\033[96m"
20
+ WHITE = "\033[97m"
21
+ GRAY = "\033[90m"
22
+
23
+ @classmethod
24
+ def set_enabled(cls, enabled: bool):
25
+ cls.ENABLED = bool(enabled)
26
+
27
+ @classmethod
28
+ def wrap(cls, text, *codes):
29
+ if not cls.ENABLED or not codes:
30
+ return str(text)
31
+ return "".join(codes) + str(text) + cls.RESET
32
+
33
+ @classmethod
34
+ def bold(cls, text):
35
+ return cls.wrap(text, cls.BOLD)
36
+
37
+ @classmethod
38
+ def dim(cls, text):
39
+ return cls.wrap(text, cls.DIM)
40
+
41
+ @classmethod
42
+ def cyan(cls, text, bold=False):
43
+ return cls.wrap(text, cls.BOLD, cls.CYAN) if bold else cls.wrap(text, cls.CYAN)
44
+
45
+ @classmethod
46
+ def green(cls, text, bold=False):
47
+ return cls.wrap(text, cls.BOLD, cls.GREEN) if bold else cls.wrap(text, cls.GREEN)
48
+
49
+ @classmethod
50
+ def yellow(cls, text, bold=False):
51
+ return cls.wrap(text, cls.BOLD, cls.YELLOW) if bold else cls.wrap(text, cls.YELLOW)
52
+
53
+ @classmethod
54
+ def red(cls, text, bold=False):
55
+ return cls.wrap(text, cls.BOLD, cls.RED) if bold else cls.wrap(text, cls.RED)
56
+
57
+ @classmethod
58
+ def magenta(cls, text, bold=False):
59
+ return cls.wrap(text, cls.BOLD, cls.MAGENTA) if bold else cls.wrap(text, cls.MAGENTA)
60
+
61
+ @classmethod
62
+ def blue(cls, text, bold=False):
63
+ return cls.wrap(text, cls.BOLD, cls.BLUE) if bold else cls.wrap(text, cls.BLUE)
64
+
65
+ @classmethod
66
+ def gray(cls, text):
67
+ return cls.wrap(text, cls.GRAY)
68
+
69
+ @classmethod
70
+ def color_app(cls, app_name, is_unknown=False, is_noise=False):
71
+ """Colors the application/protocol classification string padded to 20 chars."""
72
+ padded = f"{str(app_name)[:20]:<20}"
73
+ if is_noise:
74
+ return cls.gray(padded)
75
+ if is_unknown:
76
+ return cls.red(padded, bold=True)
77
+ upper = str(app_name).upper()
78
+ if "TLS" in upper or "HTTPS" in upper or "QUIC" in upper:
79
+ return cls.cyan(padded, bold=True)
80
+ if "HTTP" in upper:
81
+ return cls.green(padded, bold=True)
82
+ if "SSH" in upper or "DNS" in upper or "FTP" in upper or "SMTP" in upper:
83
+ return cls.blue(padded, bold=True)
84
+ return cls.yellow(padded)
85
+
86
+ @classmethod
87
+ def color_entropy(cls, entropy_val, label):
88
+ if entropy_val is None:
89
+ return cls.gray("N/A")
90
+ text = f"{entropy_val:.2f} b/B ({label})"
91
+ if entropy_val < 5.0:
92
+ return cls.green(text)
93
+ if entropy_val <= 6.8:
94
+ return cls.yellow(text)
95
+ return cls.magenta(text, bold=True)