FlowAnalyzer 0.3.8__py3-none-any.whl → 0.3.9__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.
- FlowAnalyzer/FlowAnalyzer.py +14 -13
- {FlowAnalyzer-0.3.8.dist-info → FlowAnalyzer-0.3.9.dist-info}/METADATA +2 -2
- FlowAnalyzer-0.3.9.dist-info/RECORD +9 -0
- {FlowAnalyzer-0.3.8.dist-info → FlowAnalyzer-0.3.9.dist-info}/WHEEL +1 -1
- FlowAnalyzer-0.3.8.dist-info/RECORD +0 -9
- {FlowAnalyzer-0.3.8.dist-info → FlowAnalyzer-0.3.9.dist-info}/LICENSE +0 -0
- {FlowAnalyzer-0.3.8.dist-info → FlowAnalyzer-0.3.9.dist-info}/top_level.txt +0 -0
FlowAnalyzer/FlowAnalyzer.py
CHANGED
|
@@ -3,7 +3,6 @@ import gzip
|
|
|
3
3
|
import hashlib
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
|
-
import shutil
|
|
7
6
|
import subprocess
|
|
8
7
|
from typing import Dict, Iterable, NamedTuple, Optional, Tuple
|
|
9
8
|
from urllib import parse
|
|
@@ -153,7 +152,7 @@ class FlowAnalyzer:
|
|
|
153
152
|
return hashlib.md5(f.read() + display_filter.encode()).hexdigest()
|
|
154
153
|
|
|
155
154
|
@staticmethod
|
|
156
|
-
def extract_json_file(file_name: str, display_filter: str, tshark_work_dir: str,
|
|
155
|
+
def extract_json_file(file_name: str, display_filter: str, tshark_path: str, tshark_work_dir: str, json_work_path: str) -> None:
|
|
157
156
|
command = [
|
|
158
157
|
tshark_path,
|
|
159
158
|
"-r", file_name,
|
|
@@ -168,8 +167,9 @@ class FlowAnalyzer:
|
|
|
168
167
|
"-e", "exported_pdu.exported_pdu",
|
|
169
168
|
"-e", "http.request.full_uri",
|
|
170
169
|
]
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
logger.debug(f"导出Json命令: {command}")
|
|
171
|
+
|
|
172
|
+
with open(json_work_path, "wb") as output_file:
|
|
173
173
|
process = subprocess.Popen(
|
|
174
174
|
command,
|
|
175
175
|
stdout=output_file,
|
|
@@ -177,6 +177,7 @@ class FlowAnalyzer:
|
|
|
177
177
|
cwd=tshark_work_dir
|
|
178
178
|
)
|
|
179
179
|
_, stderr = process.communicate()
|
|
180
|
+
logger.debug(f"导出Json文件路径: {json_work_path}")
|
|
180
181
|
|
|
181
182
|
if stderr and b"WARNING" not in stderr:
|
|
182
183
|
try:
|
|
@@ -185,10 +186,7 @@ class FlowAnalyzer:
|
|
|
185
186
|
print(f"[Warning/Error]: {stderr.decode('gbk')}")
|
|
186
187
|
|
|
187
188
|
@staticmethod
|
|
188
|
-
def
|
|
189
|
-
if tshark_json_path != json_work_path:
|
|
190
|
-
shutil.move(tshark_json_path, json_work_path)
|
|
191
|
-
|
|
189
|
+
def add_md5sum(json_work_path: str, md5_sum: str) -> None:
|
|
192
190
|
with open(json_work_path, "r", encoding="utf-8") as f:
|
|
193
191
|
data = json.load(f)
|
|
194
192
|
data[0]["MD5Sum"] = md5_sum
|
|
@@ -217,9 +215,10 @@ class FlowAnalyzer:
|
|
|
217
215
|
raise FileNotFoundError("您的填写的流量包没有找到!流量包路径:%s" % file_path)
|
|
218
216
|
|
|
219
217
|
md5_sum = FlowAnalyzer.get_hash(file_path, display_filter)
|
|
218
|
+
logger.debug(f"md5校验值: {md5_sum}")
|
|
219
|
+
|
|
220
220
|
work_dir = os.getcwd()
|
|
221
|
-
|
|
222
|
-
tshark_json_path = os.path.join(tshark_work_dir, "output.json")
|
|
221
|
+
tshark_command_work_dir = os.path.dirname(os.path.abspath(file_path))
|
|
223
222
|
json_work_path = os.path.join(work_dir, "output.json")
|
|
224
223
|
file_name = os.path.basename(file_path)
|
|
225
224
|
|
|
@@ -228,14 +227,14 @@ class FlowAnalyzer:
|
|
|
228
227
|
with open(json_work_path, "r", encoding="utf-8") as f:
|
|
229
228
|
data = json.load(f)
|
|
230
229
|
if data[0].get("MD5Sum") == md5_sum:
|
|
231
|
-
logger.debug("匹配
|
|
230
|
+
logger.debug("匹配md5校验无误,自动返回Json文件路径!")
|
|
232
231
|
return json_work_path
|
|
233
232
|
except Exception:
|
|
234
233
|
logger.debug("默认的Json文件无法被正常解析, 正在重新生成Json文件中")
|
|
235
234
|
|
|
236
235
|
tshark_path = FlowAnalyzer.get_tshark_path(tshark_path)
|
|
237
|
-
FlowAnalyzer.extract_json_file(file_name, display_filter,
|
|
238
|
-
FlowAnalyzer.
|
|
236
|
+
FlowAnalyzer.extract_json_file(file_name, display_filter, tshark_path, tshark_command_work_dir, json_work_path)
|
|
237
|
+
FlowAnalyzer.add_md5sum(json_work_path, md5_sum)
|
|
239
238
|
return json_work_path
|
|
240
239
|
|
|
241
240
|
@staticmethod
|
|
@@ -243,6 +242,8 @@ class FlowAnalyzer:
|
|
|
243
242
|
default_tshark_path = get_default_tshark_path()
|
|
244
243
|
if not os.path.exists(default_tshark_path):
|
|
245
244
|
logger.debug("没有检测到tshark存在, 请查看并检查tshark_path")
|
|
245
|
+
else:
|
|
246
|
+
logger.debug("检测到默认tshark存在!")
|
|
246
247
|
|
|
247
248
|
if tshark_path is None:
|
|
248
249
|
logger.debug("您没有传入tshark_path, 请传入tshark_path")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: FlowAnalyzer
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.9
|
|
4
4
|
Summary: FlowAnalyzer是一个流量分析器,用于解析和处理tshark导出的JSON数据文件
|
|
5
5
|
Home-page: https://github.com/Byxs20/FlowAnalyzer
|
|
6
6
|
Author: Byxs20
|
|
@@ -52,7 +52,7 @@ tshark_path = r"C:\Program Files\Wireshark\tshark.exe"
|
|
|
52
52
|
```
|
|
53
53
|
$ git clone https://github.com/Byxs20/FlowAnalyzer.git
|
|
54
54
|
$ cd ./FlowAnalyzer/
|
|
55
|
-
$ python
|
|
55
|
+
$ python tests\demo.py
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
运行结果:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
FlowAnalyzer/FlowAnalyzer.py,sha256=ErHea4wQEeGmCgAmWr4xmEuKSSYfXE0kFe7It0xD6Is,12203
|
|
2
|
+
FlowAnalyzer/Path.py,sha256=E5VvucTftp8VTQUffFzFWHotQEYtZL-j7IQPOaleiug,130
|
|
3
|
+
FlowAnalyzer/__init__.py,sha256=vfiHONPTrvjUU3MwhjFOEo3sWfzlhkA6gOLn_4UJ7sg,70
|
|
4
|
+
FlowAnalyzer/logging_config.py,sha256=-RntNJhrBiW7ToXIP1WJjZ4Yf9jmZQ1PTX_er3tDxhw,730
|
|
5
|
+
FlowAnalyzer-0.3.9.dist-info/LICENSE,sha256=ybAV0ECduYBZCpjkHyNALVWRRmT_eM0BDgqUszhwEFU,1080
|
|
6
|
+
FlowAnalyzer-0.3.9.dist-info/METADATA,sha256=OcwMs0sqeUmUv1Y-9NWDaGFswMupCLf-FuJYr68DQX8,1956
|
|
7
|
+
FlowAnalyzer-0.3.9.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
8
|
+
FlowAnalyzer-0.3.9.dist-info/top_level.txt,sha256=2MtvAF6dEe_eHipw_6G5pFLb2uOCbGnlH0bC4iBtm5A,13
|
|
9
|
+
FlowAnalyzer-0.3.9.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
FlowAnalyzer/FlowAnalyzer.py,sha256=AV1AGAQqJsniHvnhzXhNRg4F__sAsl6MIwqW8BGdxSI,12163
|
|
2
|
-
FlowAnalyzer/Path.py,sha256=E5VvucTftp8VTQUffFzFWHotQEYtZL-j7IQPOaleiug,130
|
|
3
|
-
FlowAnalyzer/__init__.py,sha256=vfiHONPTrvjUU3MwhjFOEo3sWfzlhkA6gOLn_4UJ7sg,70
|
|
4
|
-
FlowAnalyzer/logging_config.py,sha256=-RntNJhrBiW7ToXIP1WJjZ4Yf9jmZQ1PTX_er3tDxhw,730
|
|
5
|
-
FlowAnalyzer-0.3.8.dist-info/LICENSE,sha256=ybAV0ECduYBZCpjkHyNALVWRRmT_eM0BDgqUszhwEFU,1080
|
|
6
|
-
FlowAnalyzer-0.3.8.dist-info/METADATA,sha256=Jz4mmDZwGJscF_DsxRbHniPpg5HUb3ZmbmK4BpoikEE,1956
|
|
7
|
-
FlowAnalyzer-0.3.8.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
8
|
-
FlowAnalyzer-0.3.8.dist-info/top_level.txt,sha256=2MtvAF6dEe_eHipw_6G5pFLb2uOCbGnlH0bC4iBtm5A,13
|
|
9
|
-
FlowAnalyzer-0.3.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|