FlowAnalyzer 0.3.8__tar.gz → 0.3.9__tar.gz

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.
@@ -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, tshark_path: str) -> None:
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
- with open(f"{tshark_work_dir}/output.json", "wb") as output_file:
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 move_and_add_md5sum(tshark_json_path: str, json_work_path: str, md5_sum: str) -> None:
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
- tshark_work_dir = os.path.dirname(os.path.abspath(file_path))
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("匹配HASH校验无误,自动返回Json文件路径!")
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, tshark_work_dir, tshark_path)
238
- FlowAnalyzer.move_and_add_md5sum(tshark_json_path, json_work_path, md5_sum)
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.8
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 -m tests.demo
55
+ $ python tests\demo.py
56
56
  ```
57
57
 
58
58
  运行结果:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlowAnalyzer
3
- Version: 0.3.8
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 -m tests.demo
55
+ $ python tests\demo.py
56
56
  ```
57
57
 
58
58
  运行结果:
@@ -34,7 +34,7 @@ tshark_path = r"C:\Program Files\Wireshark\tshark.exe"
34
34
  ```
35
35
  $ git clone https://github.com/Byxs20/FlowAnalyzer.git
36
36
  $ cd ./FlowAnalyzer/
37
- $ python -m tests.demo
37
+ $ python tests\demo.py
38
38
  ```
39
39
 
40
40
  运行结果:
@@ -7,7 +7,7 @@ with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8"
7
7
 
8
8
  setup(
9
9
  name="FlowAnalyzer",
10
- version="0.3.8",
10
+ version="0.3.9",
11
11
  description="FlowAnalyzer是一个流量分析器,用于解析和处理tshark导出的JSON数据文件",
12
12
  author="Byxs20",
13
13
  author_email="97766819@qq.com",
File without changes
File without changes