pyshark修改tshark.exe默认路径

🎯 解决 PySha rk 的 TShark 路径配置难题

报错内容:

bash
1
2
3

pyshark.tshark.tshark.TSharkNotFoundException: TShark not found. Try adding its location to the configuration file. Searched these paths: ['C:\\Program Files\\Wireshark\\tshark.exe', 'C:\\Program Files (x86)\\Wireshark\\tshark.exe', 'C:\\Program Files\\Wireshark\\tshark.exe']

1️⃣ 🚨 报错解析
TSharkNotFoundException 的核心原因是:
▹ Wireshark 未安装在默认路径 ,没有找到tshark.exe
▹ PyShark 搜索路径不包含当前安装位置
2️⃣ 🛠️ 解决方案速览
▸ 临时方案 → 代码中动态指定路径
▸ 永久方案 → 修改配置文件一劳永逸

1. 临时使用方法:

代码中使用FileCapture函数时直接加入tshark的路径:

python
1
capture = pyshark.FileCapture('data.pcapng', display_filter='http',tshark_path="D:\\Tools_and_Software\\CTF\\misc\\Wireshark\\tshark.exe")

2. 一劳永逸的方法

我们可以去修改config.ini中的tshark.exe的路径。

config.ini路径在python安装路径的\Lib\site-packages\pyshark
默认路径(以python3.11版本举例)C:\Users\{用户名}\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyshark

原版:
修改前,我们先把原版备份一下,以备不时之需!

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
[tshark]
# Specify the path to the tshark executable.
# If the configured path does not exist, these locations will be searched:
# (Linux): /usr/bin/tshark
# (Linux): /usr/sbin/tshark
# (Linux): /usr/lib/tshark/tshark
# (Linux): /usr/local/bin/tshark
# (Windows): %ProgramFiles%\Wireshark\tshark.exe
# (Windows): %ProgramFiles(x86)%\Wireshark\tshark.exe
tshark_path = C:\Program Files\Wireshark\tshark.exe

[dumpcap]
dumpcap_path = C:\Program Files\Wireshark\dumpcap.exe

修改后:

代码成功运行