安装Wireshark
- 打开Wireshark主程序(如
wrs或wrs-client)。 - 在“选择应用程序”中勾选“选择需要安装的”。
- 点击“下一步”,选择需要安装的软件。
- 确认所有软件安装完成,然后点击“安装”开始安装。
使用终端界面
1 创建Wireshark命令行应用
- 在终端中输入以下命令创建 Wireshark:
wrs
- 或者使用
wrs-client:wrs-client
2 确定流量包类型
- 选择流量包:
wrs --select流量包
- 选择端口包:
wrs --select端口包
3 设置参数
- 设置流量包的大小:
wrs --select流量包 --select_size 1
- 设置包数:
wrs --select流量包 --select包数 5
4 分析流量包
- 打开流量包列表:
wrs -l
- 访问具体流量包:
wrs -l | grep 流量包
生成日志文件
- 生成日志:
wrs --log --logdir=/path/to/logdir
- 生成日志文件:
wrs --log --logdir=/path/to/logdir --log
分析流量包属性
- 观察流量包大小:
wrs --select流量包 | wc -l
- 观察包数:
wrs --select流量包 | wc -l
使用Python脚本分析
-
写Python脚本:
import pandas as pd import matplotlib.pyplot as plt # 读取日志文件 import io import sys from io import BytesIO # 连接到Wireshark的输出日志 with open(sys.stdout, 'r', buffering=65536) as f: data = f.read().splitlines() headers = data[].splitlines() data = data[1:] # 读取流量包数据 df = pd.DataFrame(data, columns=headers) df['时间'] = pd.to_datetime(df['时间']) df['流量包'] = df['流量包'].astype(str) # 绘制流量包的大小分布 plt.figure(figsize=(1, 6)) plt.hist(df['流量包'].astype(str).length, bins=range(, 1, 1), rwidth=.8) plt.title('流量包大小分布') plt.xlabel('大小(1个流量包)') plt.ylabel('流量包数') plt.grid(True) plt.show() # 绘制流量包的包数分布 plt.figure(figsize=(1, 6)) df['流量包'].value_counts().sort_values(ascending=False).plot(kind='bar') plt.title('流量包包数分布') plt.xlabel('流量包类型') plt.ylabel('包数') plt.show()
处理多端口流量包
- 打开日志文件:
wrs --log --logdir=/path/to/logdir | grep --name "端口包"
- 筛选出特定端口:
wrs --select端口包 --name '端口1' --select_size 1
处理异常流量包
- 找到异常流量包:
wrs --select流量包 | where '流量包大小 > 1'
复制和保存分析结果
- 复制日志文件:
wrs --log --logdir=/path/to/logdir > /path/to/outputs.log
- 复制Python脚本输出:
wrs --log --logdir=/path/to/logdir > /path/to/outputs.py
维护和更新
- 定期更新Wireshark和日志工具。
- 提供Wireshark的文档和支持渠道。
通过以上步骤,您可以高效使用Wireshark来分析网络流量,帮助您识别和应对网络攻击。









